Need to populate times in Change Request automatically and in its task too
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I am developing a use case where our team must create standard Change Requests from templates that run on fixed recurring schedules, such as every Tuesday at 5 PM.
Each Change Request includes sequentially timed tasks with fixed durations, such as Task 1 taking one hour and Task 2 taking three hours.
I have tried to create for specific template by creating different workflow for different CR but that is not feasible.
Is it possible to automate this using a universal Flow Designer flow that dynamically applies these schedules and task times across any standard change template?
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited 42m ago
Hello @RajputChirS
I have changed the user timezone to GMT and created below flow which means it will run in GMT and then setting the planned start and end date values in GMT.
Here is the Flow: Please add Error handler
Keep updating the targetDateTime.setDisplayValue(date + " 17:00:00"); number accordingly
Planned Start Date Code for CR and CR Task:
/*
**Access Flow/Action data using the fd_data object. Script must return a value.
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
var gdt = new GlideDateTime();
// Get today's day of week in GMT
// 1 = Monday, 2 = Tuesday, ... 7 = Sunday
var dayOfWeek = gdt.getDayOfWeekUTC();
// Calculate days until Tuesday
var daysToAdd = (2 - dayOfWeek + 7) % 7;
// If today is not Tuesday, move to upcoming Tuesday
if (daysToAdd > 0) {
gdt.addDaysUTC(daysToAdd);
}
// Get date in GMT
var date = gdt.getDate();
// Set time to 5:00 PM GMT
var targetDateTime = new GlideDateTime();
targetDateTime.setValue(date + " 17:00:00");
// If today is Tuesday AND current GMT time is past 5 PM, move to next Tuesday
if (dayOfWeek == 2 && new GlideDateTime().compareTo(targetDateTime) >= 0) {
targetDateTime.addDaysUTC(7);
}
return targetDateTime;
Planned End Date Code for CR and CR Task:
/*
**Access Flow/Action data using the fd_data object. Script must return a value.
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
var gdt = new GlideDateTime();
// Get today's day of week in GMT
// 1 = Monday, 2 = Tuesday, ... 7 = Sunday
var dayOfWeek = gdt.getDayOfWeekUTC();
// Calculate days until Tuesday
var daysToAdd = (2 - dayOfWeek + 7) % 7;
// If today is not Tuesday, move to upcoming Tuesday
if (daysToAdd > 0) {
gdt.addDaysUTC(daysToAdd);
}
// Get date in GMT
var date = gdt.getDate();
// Set time to 5:00 PM GMT
var targetDateTime = new GlideDateTime();
targetDateTime.setValue(date + " 18:00:00"); //modify me accordingly
// If today is Tuesday AND current GMT time is past 5 PM, move to next Tuesday
if (dayOfWeek == 2 && new GlideDateTime().compareTo(targetDateTime) >= 0) {
targetDateTime.addDaysUTC(7);
}
return targetDateTime;
Validation Results:
Before:
After:
Hope that helps!
