Error handling for flows - need to get information from parent flow to subflow

KimAlsgaard
Tera Contributor

Hi all,

 

I am trying to write a generic error handler for flows that should cover if for example a task is skipped, fails or not resolved correctly (as stated so in the business requirement). If an error occurs an incident should be created. The creation if the incident is no problem at all. The problem is gathering information to put into the description-field of the incident.

 

I have made a subflow, and need to get as much information as possible about the parent flow. From what I can gather by googling and checking this site, not much is being exposed. 

 

I have looked a bit at the FlowAPI without any luck, perhaps it's just a matter of putting the right things together in the right order. The FlowScriptAPI returns the context ID of the subflow, unfortunately not the parent flow.

 

It would be possible to add a call to the FlowScriptAPI in the parent script and relay that contextID to the subflow as an input, but I would like to keep as much error handling as possible within the subflow itself, so the persons building flows only need to add a call to the error handler subflow, and not having to worry about adding other steps but the call to subflow.

 

Has anybody done something like this, where the error handler should just be called from the parent flow without the need for a variable in the parent flow that states the flow name and so on? No life hack whatsoever on this issue?

1 ACCEPTED SOLUTION

Uncle Rob
Kilo Patron

This video I made a while back should show you how to do it.
Create an Error Handling Subflow with ServiceNow Flow Designer
Includes how to get flow and parent flow contexts.
https://youtu.be/Br5p7inqbXw

View solution in original post

In 15 minutes you can deploy a single subflow to all your ServiceNow Flows that require error handling. SPECIAL THANKS TO JONATHAN CROSBY https://www.linkedin.com/in/jonathancrosbyfl/ 🔎 Looking for #ServiceNow talent or opportunity? 🤝 Need coaching or mentorship? http://theduke.digital/contact/ 👑
5 REPLIES 5

Mark Manders
Mega Patron

The 'source record' on the subflow execution contains the sys id of the flow engine context. Maybe that's something you can use to do a lookup and get the information.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Uncle Rob
Kilo Patron

This video I made a while back should show you how to do it.
Create an Error Handling Subflow with ServiceNow Flow Designer
Includes how to get flow and parent flow contexts.
https://youtu.be/Br5p7inqbXw

In 15 minutes you can deploy a single subflow to all your ServiceNow Flows that require error handling. SPECIAL THANKS TO JONATHAN CROSBY https://www.linkedin.com/in/jonathancrosbyfl/ 🔎 Looking for #ServiceNow talent or opportunity? 🤝 Need coaching or mentorship? http://theduke.digital/contact/ 👑

@Uncle Rob That's a great and detailed video, thanks!

 

I almost got it to work based on it, but the description that's logged to the incident looks like this in my example:

 

CODE: 1
MESSAGE: {
"code" : 1,
"message" : "Error: This step is designed to fail intentionally. (Process Automation.2721c932fb562250bf98ff22aeefdcd6; line 3)"
}

 

I noticed in your video, that you just had a much cleaner error message. Any idea why my shows up like that?

I am using an action to manipulate an error. The only thing it does is this: 

 

(function execute(inputs, outputs) {
    // Force a failure by throwing an error
    throw new Error('This step is designed to fail intentionally.');
})(inputs, outputs);
 
Help is much appreciated 🙂

Uncle Rob
Kilo Patron

Send screenshots of the action definition and hte output you get and i'll be happy to take a look.