Check if flow variable exists

I want to add the potential error information coming out of a catch node to the json output of the workflow. I am using a JSON Transform to add the flow variables to the json. This works fine, as long as there are flow variables (errors). If there are no errors, the JSON Transform node fails and isn’t executing. How can I check if a flow variable exists and use that to control the workflow?

Thanks!

Hi there @tbtt,

not aware of node that would check variable existence. Can you check Always populate error message option in Catch Errors node and then based on it’s value control further flow? When there will be no error you will have your defined value which is none by default.

Br,
Ivan

1 Like

Hey @ipazin

just did a quick check, seems to work without any problem

Hey ipazin
I am still not 100 percent happy, I have two different try-catch blocks in branches, and the results get concatenated with a concatenate node.
Your approach leads to the 2nd flow variable being ignored, which means that if the 1st input port contains the none error message but the second input port contains a real one, after the concatenate node the actual error message is gone. Any ideas?

The Java snippet can check if a flow variable exists. It is described in the node documentation of the node.

2 Likes

Hi there @tbtt,

I see. Then you can create new flow variable after first Try/Catch sequence using String Manipulation (Variable) or Variable Expressions or Java Edit Variable (simple) node to preserve value you need. But there is node that can check variable existence so maybe you can have better solution with it. Tnx @Iris :slight_smile:

Br,
Ivan

1 Like

Thank you @Iris!
Was exactly what I was looking for! Check in JavaSnippet Node into If Switch :slight_smile:

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.