How to build conditional logic in Flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2025 06:37 AM
Hello All,
I am trying to configure the below logic in flow designer and need some help. Please advise.
I have a variable called "Productive Date" on a record producer.
1. If the Productive Date <= 30 days from current date (If today is Feb 21 it means Productive Date selected is on or before March 23, 2025), then record should be assigned to Group A.
2. If the productive date >30 days from current date (after Mar 23, 2025), then record should be assigned to Group B. However when it reaches 30 day mark, flow should assign the case back to Group A automatically.
Please advise how we can incorporate this logic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2025 06:52 AM
you can use flow variable and determine the group
use this script in Set Flow variables and then use this to set the group in the next step using Update Record flow action
/*
**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 triggerRecordSysId = fd_data.trigger.current.sys_id;
var tableName = fd_data.fd_data.trigger.current.sys_class_name;
var rec = new GlideRecord(tableName);
if(rec.get(triggerRecordSysId)){
var assignment_group = '';
var currentDate = new GlideDateTime();
var productiveDate = new GlideDateTime(rec.variables.productive_date); // give your variable name here
var groupA = 'sys_id_of_group_A'; // Replace with the actual sys_id of Group A
var groupB = 'sys_id_of_group_B'; // Replace with the actual sys_id of Group B
// Calculate the difference in days between the current date and the productive date
var daysDifference = GlideDateTime.subtract(productiveDate, currentDate).getNumericValue() / (1000 * 60 * 60 * 24);
if (daysDifference <= 30) {
// Assign to Group A
assignment_group = groupA;
} else {
// Assign to Group B
assignment_group = groupB;
// Schedule a job to reassign to Group A when it reaches the 30-day mark
var scheduledJob = new GlideRecord('sys_trigger');
scheduledJob.initialize();
scheduledJob.name = 'Reassign to Group A';
scheduledJob.script = 'var gr = new GlideRecord("' + tableName + '"); if (gr.get("' + triggerRecordSysId + '")) { gr.assignment_group = "' + groupA + '"; gr.update(); }';
scheduledJob.next_action = productiveDate.addDays(-30);
scheduledJob.insert();
return assignment_group;
}
}
I hope I have provided enough guidance
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2025 07:15 AM
Hi Ankur,
Thanks. I cannot find set flow variable action. Is there a spoke for this that we need to install?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2025 07:19 AM
click on 3 dots and create flow variable from there
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2025 07:27 AM
But i dont see the set flow variable action..