Flow designer: How to use stages in subflows?

Mathias Vandend
Mega Sage

Hi,

Since madrid we try to use the new flow designer as much as we can.

We have a large process now that we are implementing with flow designer. To be able to keep a good overview we're making use of the subflows. One thing you can't do in subflows is setting the stages like in the mainflow. So how do you set stages in a subflow?

16 REPLIES 16

can you share action.xml?

Hey @Alfonso Perez  I have been trying to implement this following yours and and Cao Hui's code but it doesn't seem to be working for me. I can update the stage_status with the new json but nothing is being reflected on the actual RITM. Can I see Step 3 and 4 on your Action for RITM Stage update? Its partially cut off on Cao Hui's document so I think I might be missing a step.

Ramesh Lohar
Kilo Guru

In ServiceNow, you cannot directly set stages in a subflow as you do in the main flow. However, you can achieve this by using the 'Flow Status' action in the subflow and then using the 'Set Values' action in the main flow to set the stage based on the status of the subflow. Here are the steps:

1. In your subflow, add a 'Flow Status' action at the points where you want to set a stage.
2. In the 'Flow Status' action, set the status to a unique value that represents the stage.
3. In your main flow, add a 'Set Values' action after the subflow.
4. In the 'Set Values' action, set the stage based on the status of the subflow. You can use a switch or if-else logic to map the status values to the stages.
5. Repeat steps 3 and 4 for each subflow in your main flow.

Please note that this is a workaround and may not be suitable for all use cases. If you need more control over the stages, you may need to use the traditional workflow editor.


nowKB.com

I have looked at the work of @Alfonso Perez and @cao hui and built a more comprehensive script on the back of their initial work.

Please see:   https://github.com/ThomasHFWright/ServiceNowScripts/blob/main/Flow%20Stage%20State%20Utils/FlowStage...

This script will return the JSON to be populated in a stage_state record for an inputted record and flow running against that record, pass in the stage to update to and it handles the rest from existing data.
It handles optional stages, previously completed stages, and skipped stages.

It does not handle including approvals in the returned stage_state object, that wasn't a requirement for me so I didn't bother.

Here's my action:

ThomasWright_0-1729248450352.pngThomasWright_1-1729248513257.png

ThomasWright_2-1729248549697.pngThomasWright_3-1729248560696.pngThomasWright_4-1729248574327.png

 

 

@Thomas Wright Hi Thomas just for understanding what are you passing into the inputs for Table? I.e what table value are you giving the action in the initial input(s)?