row action to run snippet on current row only

  • 2
  • Question
  • Updated 2 years ago
  • Answered
HI,

I wonder if anyone could help me with that.

I have this snippet that i want to use as Row Action to clear a Date field's value 
But not really sure how to get it to work on current row from which i clicked the action

This work well for 1st record of a table or on a detail page. But not on any row after the first one

I Understand it's because of 'model.getFirstRow()'  but looking at the model api documentation, I could not find what I should use instead

var $ = skuid.$,     model = skuid.model.getModel('AccountTab'),
     row = model.getFirstRow();
model.updateRow(row, {Favorite_date__c:''});
Thank you
Photo of Dave

Dave

  • 5,538 Points 5k badge 2x thumb

Posted 2 years ago

  • 2
Photo of Jeff Rutter

Jeff Rutter

  • 1,162 Points 1k badge 2x thumb
Hey Dave!

I believe I may be able to point you in the right direction here, but I'm also fairly new to the Javascript world....

In your snippet on the row you could select the specific row in say a Contact List for example by setting your variable to:


//This variable selects the rows Id field.
var contactId = params.item.row.Id;


Technically with this then you could set your variable to a value in the row and then run the updateRow method on it.

Thanks,

Jeff Rutter
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Dave,

If you're running the snippet as a row action, your snippet should get passed the 'row' as one of the arguments.
You can use something like this:

var model = arguments[0].model,
     row = arguments[0].row; model.updateRow(row, {Favorite_date__c:''});
(Edited)
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
On second thought, you might need to use arguments[0].item.row, as Jeff said.

Just add a console.log(arguments); at the beginning of your snippet, then run it and take a look at your console to see what arguments are available.
Photo of Dave

Dave

  • 5,538 Points 5k badge 2x thumb
Thank you Jeff and Matt,

As per Matt's last post , That Worked perfectly!
Photo of Jeff Rutter

Jeff Rutter

  • 1,162 Points 1k badge 2x thumb
Glad to help!