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

Experts

 

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


array.assignees -- array of structure
assignee.id
assignee.name
assigned.status
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 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

    print(diff);

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