Populate Date/Time with NOW + 1 hour

  • 1
  • Question
  • Updated 7 months ago
  • Answered
  • (Edited)
I wish to populate the EndDateTime field on my Event model with date/time of now + 1 hour. How do I achieve this? I've hacked some javascript below based on some other posts but it's failing.

var params = arguments[0],
	$ = skuid.$;

var model = skuid.$M('Event');
var row = model.getFirstRow();
var dateVar = row.EndDateTime;
//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);
Photo of Glenn Daly

Glenn Daly

  • 1,270 Points 1k badge 2x thumb
  • confused

Posted 7 months ago

  • 1
Photo of Glenn Daly

Glenn Daly

  • 1,270 Points 1k badge 2x thumb
I managed to resolve this by making some small changes to the code below. And by having the snippet run as an action when a new record is created on the model

var params = arguments[0],
	$ = skuid.$;
var model = skuid.$M('Event');
var row = model.getFirstRow();
var dateVar = new Date();
var jsDate = skuid.time.parseSFDateTime(dateVar);
jsDate.setHours(jsDate.getHours() + 1);
var hourAdded = skuid.time.getSFDateTime(jsDate);
model.updateRow(row,{EndDateTime : hourAdded});
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Hi Glenn, thank you for closing the loop and sharing the resolution on this!