Subtract dates in input action in the xMatters Integration Agent (IA)

Posted by Travis DePuy  I  May 30, 12

Did you know that you can subtract dates in input action in the xMatters Integration Agent (IA) JavaScript? Dates and JavaScript are always complicated. So, to prevent others from going through the headaches I’ve gone through figuring out the best way to work with dates in JS, please keep reading. My solution assumes the dates are coming from a web-service call, such as via an application integration.

describe the image

First, get this JavaScript from the web to be used as an included JavaScript library. Then, in your input action scripting, use this:

    openTime = xmlDateToJavascriptDate( incident.Submitted );
    mod_Time = xmlDateToJavascriptDate( incident.Last_Modified_Date );
    hours_open = Math.floor(parseInt( mod_Time - openTime) / (1000*60*60));
    apxml.setToken( "hours_open", hours_open );

Make sure to include the JavaScript library you just downloaded from the web:


The "-" operator for Date apparently returns the milliseconds, so we have to massage it a bit to get the number of hours, hence the calculation above. I hope this helps others!

Tags:  xMatters