Issue with getting API error code and message from action to sub flow in flow designer

Snehal13
Kilo Sage

1.  My action script is below 

(function execute(inputs, outputs) {
    
    var response = JSON.parse(inputs.response);
    outputs.responsedata.code = response.errorCode;
    outputs.responsedata.message = response.message;        

})(inputs, outputs);

So the output of action script is an object

Snehal13_0-1746978162791.png

Output of action, it's an object type

 

Snehal13_1-1746978214095.png

 

I want to get API error code and message in subflow as this - if loop to check if code is 1 or 0 but the subflow is not working. 

 

Sub flow if condition on Action-REST Step-Code data pill -   no match found

Snehal13_0-1746977924124.png

 

Why the object is not showing values under it

1 ACCEPTED SOLUTION

Robert H
Mega Sage

Hello @Snehal13 ,

 

Just defining the Object as an Output Variable is not enough.

You also need to define its properties that you are populating in the script. You do that by clicking the small (+) icon on the ResponseData output variable:

 

RobertH_0-1746981746869.png

 

You will also have to add one more line to the script:

(function execute(inputs, outputs) {
    
    var response = JSON.parse(inputs.response);
    outputs.responsedata = {}; // add this line
    outputs.responsedata.code = response.errorCode;
    outputs.responsedata.message = response.message;        

})(inputs, outputs);

 

Regards,

Robert

 

View solution in original post

7 REPLIES 7

Hello @Snehal13 ,

 

Ok, and what are the results when you use the built-in Test feature to test the Action/Flow?

 

For example, I have created an Action like yours, but using a simplified script step:

(function execute(inputs, outputs) {
    
    outputs.responsedata = {};
    outputs.responsedata.code = "100";
    outputs.responsedata.message = "my message";

})(inputs, outputs);

 

When testing the Action the results are as expected, both for the script step and the overall action output:

 

RobertH_0-1746987083350.png

 

If you can test with a similar simplified script and get the expected outputs then it means your Action is configured correctly, but there must be some issue in your actual script or the input, probably something very subtle.

 

Regards,

Robert

 

Thanks for all your help. I will debug from here. Something minor missing. everything is fine- action output, API response 

DanielCordick
Mega Patron
Mega Patron

This is a duplicate of 

 

https://www.servicenow.com/community/developer-forum/how-to-get-response-code-and-response-message-f...

 

Why open another question when you already had one going?