Skip to main content

Hello,

I’m looking for a way to mass update a field on rows selected via mass actions, but depending on another field’s value, to update a different field

Example:

If Type__c = ‘New’  I want to update the field ‘Date_Paid__c’ (date/time) to “today”
If Type__c= ‘Existing’ I want to update the field ‘Date_Paid_Existing__c’ (date/time) to “today”


my table may contain a mix of both type, and we do not want to have to do it in 2 different actions.

I would like to be able to accomplish this from 1 Mass action.

Probably can be done with a snippet, so if anyone has ever attempted something similar, please let me know how, as i’m a JS noob 😦

Thank you 


Dave you are headed directly to the dark side.  This will require some Javascript to take care of. 


That was what worried me ;sweat

In case, have you or anyone else ever done something similar? and if yes could you please share that snippet so I have a base to work with?


Thank you


Hi Dave

Add this snippet as a mass action:


var params = arguments[0],<br> $ = skuid.$;<br><br>var model = params.model;<br><br>var list = params.list;<br><br>var selectedItem = params.item ? [params.item] : list.getSelectedItems();<br><br>$.each( selectedItem,<br>function( i, item )<br>{<br> row = item.row;<br> <br> if(row.Type__c === 'New'){<br> model.updateRow(row,{<br> Date_Paid__c: new Date()<br> });<br> }else if(row.Type__c === 'Existing'){<br> model.updateRow(row,{<br> Date_Paid_Existing__c: new Date()<br> });<br> }<br>});<br><br>model.save();

Hope that helped…


Thank you very much JG!,


It seems to work but I get an error when it’s trying to save



I think it’s my fault, As looking at post, I made a mistake, that field is of “Date” format and Not “Date/Time”


I tried couple different thing , i found on google to fix it, but does not seem to work , closest i got was adding this:


var today = new Date();


today.setHours(0, 0, 0, 0); But also gave a similar error What would i need to do for this snippet to input today without time? Thank you again and sorry about that mistake I made

I think you need to translate your “today” value from a javascript date time field into a legitimate salesforce date/time field .

Fortunately Skuid provides a utility for this.  

Add code that looks like this: 


var today = new Date();<br>today.setHours(0, 0, 0, 0);<br>var sf_today = skuid.time.getSFDateTime(today)


 Then pass the sf_today value into your update row declarations. 


Ty Rob, but that gives me the same error.


As i explained on post earlier the fields to update are of “DATE” format and not “DATE/TIME”.


So i tried to modify this to:


var today = new Date();


today.setHours(0, 0, 0, 0);
var sf_today = skuid.time.getSFDate(today) But same issue. I can see the proper date In field, but it will not allow saving, because i think it's trying to add the "time" to this date field I need to update with today's date only, not date/time Thx

Try:


today = skuid&#46;time&#46;getSFDate(new Date());

That works fine for me…


Ty JG for correct syntax,

now it works perfectly ! 🙂