How to diff of two Date& Time fields using FAFR

How to diff of two Date& Time fields using FAFR

If you have two date and time additional fields or default fields, and if you want to capture the difference between those two fields in Hours and minutes, then use the below script to capture the value in an additional field,

Under the respective Incident/Change template FAFR,provide the necesary criteria and  under Actions, select Execute script and provide the below script,

var x=$CS.getValue("WorkOrder_Fields_UDF_DATE1");

var y=$CS.getValue("WorkOrder_Fields_UDF_DATE2");

var z=y-x;

var a=z / (60 * 60 * 1000);

var b=z / (60 * 1000) % 60;

var c=parseInt(a)+" hours"+parseInt(b)+" minutes";

$CS.setValue("WorkOrder_Fields_UDF_CHAR1",c); ( Here Workorder_Fields_UDF_CHAR1 is the custom field which shows the Hours and minutes).

 

The above script if you input two Date and Time values, then the output will display in the below format,

 

 


                  New to ADSelfService Plus?

                    • Related Articles

                    • Script to Populate User Additional Field under Incident Template using FAFR

                      The script load the Requester Name under Incident Additional field ( As a pick list), by choosing the requester name under additional field the script populates the user additional field value. * Kindly create two additional fields under Admin -> ...
                    • Script to set fields from CSV using FAFR.

                      Works in 10604 Requirement: Load Data from CSV depending on the value selected in an additional field. Usecase: Assume there are 3 additional fields for a request template, namely, "Reference number", "Payment type and "Vendor". "Reference number" is ...
                    • FAFR - Sample script to have the additional field value appended to the actual subject line

                      Here is a sample script to be used in FAFR to have the additional field info appended to the actual subject line, var contract=$CS.getValue("WorkOrder_Fields_UDF_CHAR5"); var subject=$CS.getValue("SUBJECT"); var new_subject = subject + " : " + ...
                    • How to disable the Created Date field for technicians

                      1. Roles Under Admin >> Roles >> Disable the below access The above option will disable the user from modifying Created Date, Resolved Date, Dueby Time. 2. Field and Form Rules If the requirement is to disable only Created Date field.  Under Admin >> ...
                    • Script to find the actual SLA of an Incident

                      Use case When an incident is logged, the timer for the SLA is started. However, the actual incident might have occurred hours before the incident creation. In order to find the actual time of SLA,  we can use a python script.  Pre-requisite  Python ...