- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 05:35 PM
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?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:05 PM
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;
}
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 05:46 PM - edited 03-05-2024 05:51 PM
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
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 06:19 PM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 06:21 PM
Do I need to run this in a "Run Script" action?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:05 PM
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;
}
Harish