- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 07:02 AM
We have a variable named as - "How many tasks required" - Options will be -
1. One task
2. Two tasks
3. Three tasks
Depending of fulfiller's selection tasks are generating
Now the requirement is - (We are not sure how many tasks are going to select by fulfiller)
Condition First - If any one task is in closed incomplete state and others are closed complete or closed skipped than, state of RITM should state as "closed Incomplete"
Condition Second- If any one task is in closed complete and others are in closed skipped than, state of RITM should be state as "Closed Complete"
Condition Third- If all tasks are in closed skipped than state of RITM should state as "Closed Skipped"
How can we achieve this using flow designer.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 09:10 AM
Hello @Pratiksha KC ,
Here's a sequence to consider, assuming that all tasks are created in parallel:
- Create a new flow with a trigger condition of SCTASK is updated with the conditions:
- Active changes to false AND
- Item is your catalog item for the request
- Create four integer Flow Variables:
- incomplete_state
- complete_state
- skipped_state
- open_tasks
- In the first step, use Set Flow Variables to set the Data value for all four Flow Variables to 0
- Then, use the Look up records action with the conditions of:
- Item is your catalog item
- RITM is the parent RITM of the current SCTASK record
- Next, use the For Each action and drag set the Items as the records that were looked up in the previous step
- In the For Each action branch, create the following logic:
- If state == closed_incomplete
- Set the flow variable value of incomplete_state to increment up by 1
- Else if state == closed_complete
- Set the flow variable value of complete_state to increment up by 1
- Else if state == closed_skipped
- Set the flow variable value of skipped_state to increment up by 1
- Else
- Set the flow variable value of open_tasks to increment up by 1
- Note: To increment the flow variables, you will use the Set Flow Variables action.
- Choose the applicable flow variable from the dropdown
- Drag the data pill of the same flow variable to the new value section
- Hover over the data pill you just added to show, and then select, the Transform Functions option
- Under the Math transform section, select the Add option, and set the Number to 1
- Click Apply
- See example image below
- If state == closed_incomplete
- After the For Each action (back on the main branch of the Flow), create the following logic:
- If incomplete_state is greater than or equal to 1 AND open_tasks is 0
- Update the RITM to closed_incomplete state
- Else if complete_state is greater than or equal to 1 AND open_tasks is 0
- Update the RITM to closed_complete state
- Else if skipped_state is greater than or equal to 1 AND open_tasks is 0
- Update the RITM to closed_skipped state
- Update the RITM to closed_skipped state
- Note: I did not add an "Else" statement here, because if there are any open tasks, we don't want to take action on the RITM until the remaining tasks have been closed
- If incomplete_state is greater than or equal to 1 AND open_tasks is 0
One more consideration to add: You may want to create this as a Subflow if there is any chance that this logic is to be repeated on any other Flow. To do this, you would complete steps 2-7 in the Subflow record. The Subflow would have two inputs: an SCTASK record, and a Catalog Item record. Your Flow would still be set up as outlined in step 1, and then you would add the Subflow as your first step, and pass in the input values.
Image referenced in step 6:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 09:40 AM - edited 07-21-2025 09:40 AM
Hello @Pratiksha KC ,
Yes, this requirement is definitely achievable using Flow Designer only—everything can be handled within a single flow.
I had a bit of free time today, so just quickly tried and tested the logic in my personal developer instance (PDI), and it’s working exactly as expected 🙂
Let me walk you through the approach step-by-step so you can set this up on your side:
-
Step 1: Add a "Get Flow Variables" Step
Start by adding a "Get Flow Variables" action in your flow to retrieve the value of your catalog variable:Variable name: how_many_tasks_required
The output from this is used in the script to determine how many tasks to expect.
-
Flow Variable Logic
First, I created a flow logic variable which does all the work in script and acts as a decision-maker for what the RITM’s state should be based on the states of its generated catalog tasks. -
Placed Flow Variable Calculation After Task Creation
This flow variable step is placed after all your catalog tasks are created (so that their states can be correctly evaluated), and before you update the RITM’s state. -
Script Used in the Flow Variable Step
Here's the exact script I used inside the flow logic variable:/** * Script inside Flow Designer → Script step (Logic) */ // Get the current RITM's sys_id var ritmSysId = fd_data.trigger.request_item; // Get the catalog variable value from flow variables var taskCountVar = fd_data._1__get_catalog_variables.how_many_tasks_required; // Map variable value to expected task count var expectedTaskCountMap = { 'one_task': 1, 'two_tasks': 2, 'three_tasks': 3 }; var expectedTaskCount = expectedTaskCountMap[taskCountVar] || 0; // Query catalog tasks related to this RITM var taskGR = new GlideRecord('sc_task'); taskGR.addQuery('request_item', ritmSysId); taskGR.query(); // Initialize counters var countComplete = 0; var countIncomplete = 0; var countSkipped = 0; var totalTasks = 0; // Loop through the tasks and count states while (taskGR.next()) { totalTasks++; var taskState = taskGR.getValue('state'); if (taskState === '3') { countComplete++; } else if (taskState === '4') { countIncomplete++; } else if (taskState === '7') { countSkipped++; } } // Determine RITM state based on task states var ritmState = null; if (countIncomplete > 0) { ritmState = 4; // Closed Incomplete } else if (countComplete > 0 && (countComplete + countSkipped === totalTasks)) { ritmState = 3; // Closed Complete } else if (countSkipped === totalTasks && totalTasks > 0) { ritmState = 7; // Closed Skipped } // Return the new state to be used in Update Record return ritmState;
and then you can simple use this flow variables output to set or update the RITM's state.
adding few screenshots just for your understanding.
FYI- I did not added the dynamic catalog task function since you were not facing any blockers there.
-
Place both the Script Logic and Update Record steps after your Catalog Task creation.
-
This way you can keep all processing within Flow Designer.
-
The script as written covers the three main conditions:
-
If any task is Closed Incomplete, the RITM is set to Closed Incomplete.
-
If at least one task is Closed Complete and the rest are Closed Skipped, the RITM is set to Closed Complete.
-
If all tasks are Closed Skipped, the RITM is set to Closed Skipped.
-
-
You can test this flow by setting up various task state combinations and confirming the RITM moves to the correct state.
Consider that, depending on how many tasks are created and what states they reach, you may wish to extend this logic further in the future to support additional scenarios.
Let me know if you have any questions or need further clarification.
🔹 Please mark ✅ Correct if this solves your query, and 👍 Helpful if you found the response valuable.
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 07:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 08:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 08:54 AM
Hi @Pratiksha KC ,
To achieve this using Flow, first create a subflow that iterates through the associated catalog tasks (SCTASKs) of the RITM, counts the occurrences of each relevant state (Closed Complete, Closed Incomplete, Closed Skipped), and updates the RITM state based on the specified conditions. For example, if any SCTASK is in a "Closed Incomplete" state, set the RITM state to "Closed Incomplete". If any SCTASK is in "Closed Complete" and none are in "Closed Incomplete", set the RITM state to "Closed Complete". If all SCTASKs are in "Closed Skipped", set the RITM state to "Closed Skipped".
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 09:03 AM
you can use after update business rule and update the RITM state
After Update: sc_task
Condition: State [Changes to] [Close Complete or Closed Incomplete or Close Skipped]
Script:
// Table: sc_task
// When: after update
// Condition: current.request_item.changes() -- or always if you want
(function executeRule(current, previous /*null when async*/) {
var ritmID = current.request_item;
if (!ritmID) return;
// Query all tasks for this RITM
var grTask = new GlideRecord('sc_task');
grTask.addQuery('request_item', ritmID);
grTask.query();
var total = 0;
var closedComplete = 0;
var closedSkipped = 0;
var closedIncomplete = 0;
while (grTask.next()) {
total++;
switch (grTask.state.toString()) {
case '3': // Closed Complete
closedComplete++; break;
case '7': // Closed Skipped
closedSkipped++; break;
case '4': // Closed Incomplete
closedIncomplete++; break;
}
}
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(ritmID)) {
var newState = null;
// --- Logic per your requirements ---
// All Closed Skipped
if (closedSkipped == total) {
newState = 7; // Closed Skipped
}
// Any Closed Incomplete, and all others are Closed Skipped or Closed Complete
else if (closedIncomplete > 0 && (closedIncomplete + closedComplete + closedSkipped) == total) {
newState = 4; // Closed Incomplete
}
// Any Closed Complete, all others are Closed Skipped
else if (closedComplete > 0 && (closedComplete + closedSkipped) == total) {
newState = 3; // Closed Complete
}
// Update RITM state if needed
if (newState && ritm.state != newState) {
ritm.state = newState;
ritm.update();
}
}
})(current, previous);
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