- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 04:12 AM
Hi, Calculate number days between two dates in flow designer. Check condition for start date and end date in catalog variable. If it is more than 30 days, need to calculate the number of days and also create catalog task with short description like "System Administrator has taken leave for 33 days", and assignment group is populated with Help desk.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 05:26 AM
HI @praveen_rajan ,
I trust you are doing great.
Start by setting up a Flow Designer flow.
Add two catalog variables, "Start Date" and "End Date", to capture the date inputs from the users.
Use a condition element to check if the difference between the start and end dates is more than 30 days.
You can use JavaScript code to calculate the number of days between two dates. Here's an example:
var startDate = new Date(input.StartDate);
var endDate = new Date(input.EndDate);
var timeDiff = endDate.getTime() - startDate.getTime();
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 08:03 AM
something like this
var dt = new GlideDateTime('<startDate>');
var end = new GlideDateTime('<endDate>');
var dur = GlideDateTime.subtract(dt,end);
var days = dur.getDayPart();
if(days > 30){
return 'System Administrator has taken leave for 33 days';
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 04:19 AM
you can use f(x) inline script while creating catalog task and use that script to set short description
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 04:39 AM
Can you share the script please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 08:03 AM
something like this
var dt = new GlideDateTime('<startDate>');
var end = new GlideDateTime('<endDate>');
var dur = GlideDateTime.subtract(dt,end);
var days = dur.getDayPart();
if(days > 30){
return 'System Administrator has taken leave for 33 days';
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 05:26 AM
HI @praveen_rajan ,
I trust you are doing great.
Start by setting up a Flow Designer flow.
Add two catalog variables, "Start Date" and "End Date", to capture the date inputs from the users.
Use a condition element to check if the difference between the start and end dates is more than 30 days.
You can use JavaScript code to calculate the number of days between two dates. Here's an example:
var startDate = new Date(input.StartDate);
var endDate = new Date(input.EndDate);
var timeDiff = endDate.getTime() - startDate.getTime();
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi