Calculate duration from variable in a Catalog item.

Joe Taylor
Giga Guru

I am still working with workflows, not flows.

 

I have a need to flag an SCTASK as a high priority if the entered in the date/time variable on my form is less than 4 hours from the current date/time.

 

1.  There is a field called "Request Date/Time" which uses javascript:gs.nowDateTime() for the default value.

2. There is a second field called "Requested Due Date/Time" which uses the Date/Time variable.

3.  I have a third variable called Urgency which is either "Normal" or "Urgent".

 

I want to sent the urgency to "Urgent" if "Requested Due Date/Time" - "Request Date/Time" is < 4 hours.

 

What's the best way to do this?

 

 

1 ACCEPTED SOLUTION

Hi @Joe Taylor I have updated your code

var reqDateTime = new GlideDateTime(current.variables.request_date_time); // get the request date/time
var reqDueDateTime =new GlideDateTime(current.variables.request_due_date_time);

// calculate the difference in milliseconds
var diff = reqDueDateTime.getNumericValue() - reqDateTime.getNumericValue();
// convert the difference to hours
var hours = diff / (1000 * 60 * 60);
if (hours < 4) {
task.priority == 1;
}

 

 
Regards
Harish

View solution in original post

5 REPLIES 5

Harish KM
Kilo Patron
Kilo Patron

Hi @Joe Taylor you can do like this in your catalog task activity

var reqDateTime = new GlideDateTime(current.variables.VariableName); // get the request date/time
var reqDueDateTime = new GlideDateTime(current.variables.VariableName); // get the Due date/time

// calculate the difference in milliseconds
var diff = reqDueDateTime.getNumericValue() - reqDateTime.getNumericValue();

// convert the difference to hours
var hours = diff / (1000 * 60 * 60);

if (hours < 4) {
gs.info("less than 4");

set the urgency value here
}

else

{

// logic here

}

Regards
Harish

Joe Taylor
Giga Guru

Here's the code I have in the catalog task in the workflow.

This is NOT working:

 

 

var reqDateTime = current.variables.request_date_time.getDisplayValue(); // get the request date/time
var reqDueDateTime = current.variables.request_due_date_time.getDisplayValue();; // get the Due date/time
// calculate the difference in milliseconds
var diff = reqDueDateTime.getNumericValue() - reqDateTime.getNumericValue();
// convert the difference to hours
var hours = diff / (1000 * 60 * 60);
if (hours < 4) {
task.priority == 1;
}

 

Joe Taylor
Giga Guru

Do I need to run this in a "Run Script" action?

Hi @Joe Taylor I have updated your code

var reqDateTime = new GlideDateTime(current.variables.request_date_time); // get the request date/time
var reqDueDateTime =new GlideDateTime(current.variables.request_due_date_time);

// calculate the difference in milliseconds
var diff = reqDueDateTime.getNumericValue() - reqDateTime.getNumericValue();
// convert the difference to hours
var hours = diff / (1000 * 60 * 60);
if (hours < 4) {
task.priority == 1;
}

 

 
Regards
Harish