snippet populating date varies according to user's Time Zone setting

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I have a snippet which is prepopulating a dateTime field, from a previous row in the same model, OR if there are no previous rows, then date should be null and time 00:00

This seems to be working fine in our dev org and packaging org, but in a test org the 'time' component (which should be 00:00) actually varies according to the user's time zone setting.

How it looks in the dev org when first row is populated:

How it looks in the test org when first row is populated: (user's time zone set to GMT+2)

How it looks in the test org when user's time zone is reset to GMT+10

Any ideas as to why this could be happening? And how to make this snippet populate a 00:00 value for the time (across multiple orgs and user time zone variations)

Snippet below:

var $ = skuid.$,      params = arguments[0],
   model = params.model,
// Create a new row in our Model,
// with the stack__Date__c field defaulted to the same date as the last row in the table   
rows = model.getRows(),
numRows = rows.length,
        // If we have a previous row, default it to that rows date  
if (numRows) defaultDate = rows[numRows-1].stack__Date__c;
        // Otherwise default it to NOW / TODAY
        //else defaultDate = 'TODAY';
else defaultDate = null;
//Create the row
        {field: 'stack__Date__c', value: defaultDate}
    editModeForNewItems: true,
    doAppend: true
Photo of Greg Jarrett

Greg Jarrett

  • 3,526 Points 3k badge 2x thumb

Posted 4 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 43,156 Points 20k badge 2x thumb
Basically, date/time fields leaving/entering the object do not use time zones. Everything is UTC ("+0000").

So, basically, convert everything to that time zone before saving it in SF.