Time difference on MRVS

MonicaW
Tera Guru

I have a multi-row variable set with one variable in it that is a Date/Time variable.  I'm running a script in the workflow to place the values from the MRVS into the work notes.  When doing so, the Date is fine but the time is 4 hours after the time that is in the variable set.  I have tried several things like using getDisplayValue in the MRVS loop part of the script, but when I do that, the work notes show "undefined" for the values.  Any help/suggestions are appreciated!

2 REPLIES 2

Its_Azar
Mega Sage

Hi there @MonicaW 

 

can u share tthe script

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,
Azar
Serivenow Rising Star
Developer @ KPMG.

Tanushree Maiti
Mega Patron

Hi @MonicaW 

 

You are getting the issue for time difference between UTC and local time.

To fix your issue , you must initialize a GlideDateTime  object with the MRVS value and then use the getDisplay() method to convert it back to the local timezone.

 

Refer:KB0594666 Problems with using gs.nowDateTime() or GlideDateTime.getDisplayValue() in a GlideDateTime... 

 

Sample code/ not tested/ update it as per your requirement:

 

var mrvs = current.variables.your_mrvs_internal_name; // replace your mrvs var name
var mrvsData = JSON.parse(mrvs);
var workNotesMsg = "MRVS Data:\n";
for (var i = 0; i < mrvsData.length; i++) {
var testDateTime = mrvsData[i].your_date_time_variable;
var gdt = new GlideDateTime(testDateTime);
var localDateTime = gdt.getDisplayValue(); //Retrieve formatted display value (local to the user/system)
workNotesMsg += "Row " + (i + 1) + " Date/Time: " + localDateTime + "\n";
}
current.work_notes = workNotesMsg;

 

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: