- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 05:54 AM
Hi all, using if condition in workflow need to find the difference between two dates (start date and end date entered in catalog variable), if the difference date is more than 10 days, need to assign any value to assignment group in ServiceNow.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 06:23 AM
You need to write advance code as below:
var gdt1 = GlideDateTime(variable.<start_date>);
var gdt2 = GlideDateTime(variable.<start_date>);
var duration1 = gs.dateDiff(gdt1.getDisplayValue(), gdt2.getDisplayValue(), false); // this will return the difference in seconds
var tendays = 10*24*60*60; // Convert 10 days into seconds
if(duration1>tendays)
{
return 'yes';
} else {
return 'no';
}
Now based on If or Else you can Set Value of Assignment Group.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 06:37 AM - edited ‎05-18-2023 06:39 AM
I would have a Run Script at the beginning of my workflow where I calculate the date difference and then convert it into days and store that information in a scratchpad variable so it can be used throughout the workflow. Like the following:
var startDate = new GlideDateTime(current.variables.start_date);
var endDate = new GlideDateTime(current.variables.end_date);
var diff = gs.dateDiff(startDate.getDisplayValue(),endDate.getDisplayValue(),true); //This would return seconds
var days = diff/86400; //Convert the seconds to Days
workflow.scratchpad.numberOfDays = days;
//If you wanted to assign the RITM to a assignment group you could do this:
//if(workflow.scratchpad.numberOfDays > '10'){
// current.assignment_group = '679434f053231300e321ddeeff7b12d8';//Help Desk Assignment Group
//} else {
// current.assignment_group = '477a05d153013010b846ddeeff7b1225';//App Enginge Studio Team
//}
From there, in the Script section of a Catalog Task (check Advanced checkbox), you could set the assignment group like this:
if(workflow.scratchpad.numberOfDays > '10'){
task.assignment_group = '679434f053231300e321ddeeff7b12d8';//Help Desk Assignment Group
} else {
task.assignment_group = '477a05d153013010b846ddeeff7b1225';//App Enginge Studio Team
}
Just replace the sys_ids above with the sys_ids from your instance for the groups you want to assign to.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 06:23 AM
You need to write advance code as below:
var gdt1 = GlideDateTime(variable.<start_date>);
var gdt2 = GlideDateTime(variable.<start_date>);
var duration1 = gs.dateDiff(gdt1.getDisplayValue(), gdt2.getDisplayValue(), false); // this will return the difference in seconds
var tendays = 10*24*60*60; // Convert 10 days into seconds
if(duration1>tendays)
{
return 'yes';
} else {
return 'no';
}
Now based on If or Else you can Set Value of Assignment Group.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 07:39 AM
Please Elaborate how to set the assignment group based on If else condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 06:37 AM - edited ‎05-18-2023 06:39 AM
I would have a Run Script at the beginning of my workflow where I calculate the date difference and then convert it into days and store that information in a scratchpad variable so it can be used throughout the workflow. Like the following:
var startDate = new GlideDateTime(current.variables.start_date);
var endDate = new GlideDateTime(current.variables.end_date);
var diff = gs.dateDiff(startDate.getDisplayValue(),endDate.getDisplayValue(),true); //This would return seconds
var days = diff/86400; //Convert the seconds to Days
workflow.scratchpad.numberOfDays = days;
//If you wanted to assign the RITM to a assignment group you could do this:
//if(workflow.scratchpad.numberOfDays > '10'){
// current.assignment_group = '679434f053231300e321ddeeff7b12d8';//Help Desk Assignment Group
//} else {
// current.assignment_group = '477a05d153013010b846ddeeff7b1225';//App Enginge Studio Team
//}
From there, in the Script section of a Catalog Task (check Advanced checkbox), you could set the assignment group like this:
if(workflow.scratchpad.numberOfDays > '10'){
task.assignment_group = '679434f053231300e321ddeeff7b12d8';//Help Desk Assignment Group
} else {
task.assignment_group = '477a05d153013010b846ddeeff7b1225';//App Enginge Studio Team
}
Just replace the sys_ids above with the sys_ids from your instance for the groups you want to assign to.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 07:56 AM
how to insert (return "yes" and return "no") inside your code??