How to add 1 hour to a DateTime field in Multiple Actions?

  • 2
  • Question
  • Updated 4 years ago
  • Answered
  • (Edited)
I have a DateTime field that I would like to add 1 hour to in a multiple action.

I have set the multiple action to update the destination field (which is also a DateTime field and both are selected in the Model) by setting the option to a specific date and then I used {{$Model.Modelname.data.0.field}} as the value but I am not sure of the syntax or format to add 1 hour to the value?
Photo of Gregg Baxter

Gregg Baxter, Official Rep

  • 3,080 Points 3k badge 2x thumb
  • uneducated

Posted 4 years ago

  • 2
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,026 Points 20k badge 2x thumb
This is almost always going to be a javascript statement.  Fortunately - one of the actions you can invoke in the actions framework is a "snippet"    The snippet you'd write would convert the date/time field to a javascript object.  Add an hour to that object,  convert it back to a salesforce object and then save the field. 

Should be pretty straightforward. 
Photo of Gregg Baxter

Gregg Baxter, Official Rep

  • 3,080 Points 3k badge 2x thumb
Thanks Rob.

For us Javascript newbies do you have a sample pleeeaaaase?
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Your probably going to want to check out this doc : http://help.skuidify.com/m/11720/l/129505-skuid-time but something like this might work...

var params = arguments[0],   $ = skuid.$;
var model = skuid.$M('YOURMODEL');
var row = model.getFirstRow();
var dateVar = row.Your_Date_Field__c;
//convert from Salesforce date to Javascript date
var jsDate = skuid.time.parseSFDate(dateVar);
//add an hour 
jsDate.setHours(jsDate.getHours() + 1);
//convert from Javascript date back to Salesforce date
var hourAdded = skuid.time.getSFDate(jsDate);
model.updateRow(row,{Your_Date_Field__c : hourAdded});
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
If you're using a datetime field change "parseSFDate" and "getSFDate" to "parseSFDateTime" and "getSFDateTime".
Photo of Gregg Baxter

Gregg Baxter, Official Rep

  • 3,080 Points 3k badge 2x thumb
Thanks Moshe.  

You are a *  !!!