Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Date / time difference between SM Date/time fields in JS



I am trying to do this date / time difference calculation in an array of structure field, which contains

array.assignees -- array of structure
assigned.time - (date/time)
resolve.time - (date/time)


if (! system.functions.same(vars.$file.array_assignees[x].assigned_status,vars.$file0.array_assignees[x].assigned_status) && vars.$file.array_assignees[x].status == "Completed")	{
	y = x +1;
	d1 = new XMLDate(vars.$file.array_assignee[x].assigned_time)
	d2 = new XMLDate(vars.$file.array_assignee[y].assigned_time)
	var jsD1 = d1.JSDate()
	var jsD2 = d2.JSDate()
	var diff = jsD2 - jsD1
	vars.$file.assignee_array[x].resolve_time = diff


This is erroring out, with cannot store a number into an date/time field type.


Any guidance ?


I am Listening..
1 Reply
Acclaimed Contributor.
Acclaimed Contributor.

Re: Date / time difference between SM Date/time fields in JS

I feel you've to convert the difference you get back to Service Manager-formatted date/time object (Datum) before you try to push it back to $File.


Check the SM help which topic is "JavaScript method: XMLDate.getDatum()" and try the conversion tricks that doc displays.


Just for curiosity, in you put


 to your code before assigning that value to $file, what kind of values does that variable contain?

Moving on, this account is no longer active. Best regards, Kelalek
- So Long, and Thanks for All the Fish
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.