Flow Variable not being picked up by script step - Flow Designer

Robert T
Tera Contributor

Greetings,

We have an action which makes a rest call to our monitoring service.  It then returns a json string, from which we need a single field.

We attempted to use the built-in JSON parser to grab that field, but (at the recommendation of HI support) were told to just use a custom script.

That custom script works, and then it stops working because the step itself refuses to accept the variable (the JSON string).  I made a HI ticket for this problem, but the response is slow and so far not helpful, so I thought I would post here.

Here is the script step and script:

find_real_file.png

 

Here is an execution where that input variable jsonString is acquired and used.  You'll see that accepts the JSON body from the REST string and passes it into the field :

find_real_file.png

 

Then there are occasions where we test the same device and the jsonSTRING input variable is simply not defined by the script step, and the entire flow hangs, waiting indefinitely for that variable that never comes:

 

find_real_file.png

The execution log does not have a row for the input variable.  Obviously, the script does not run because it needs that value.

Any info, help, references, even a suggested change to how we are doing this are welcome.

 

Thanks.

1 ACCEPTED SOLUTION

Hi Robert. Were you able to try out the steps I mentioned to see if that corrects your issue?

View solution in original post

8 REPLIES 8

DScroggins
Kilo Sage

Hi Robert,

 

From your example screenshot the response you are receiving does not have any values in the devices array. This would make sense why your objid output variable is empty. Your action and script are correct but the response needs to return those values. That would not be an issue on ServiceNow side. Hopefully that helps. 

 

---David

The Flow itself uses the action to check if there is an object.  When there is, the flow updates it with the objid, when there is not, the flow creates the object.

This is all functional to the way we are using it.

Ultimately do you see that the second instance of the script does not even call the input variable?  (In the first one it calls the JSON which is empty, demonstrating that even if it is empty sometimes it still calls it).

Forgive me if I'm missing something here. Your action has a REST step followed by the script step you listed. The script step takes the REST step response_body as an input then parses the JSON object. From the parsed object you are trying to grab an objid from the first item in the devices array. This is where it'll be empty when nor present like the response body shown in the screenshot. You are then trying to assign that value to the output objid. The problem you are facing is when that value is blank the scrip hangs. Is this correct? If so that's because you are trying to access a parameter which doesn't exist. Try either wrapping your script in a try/catch block or you can check for the existence of the parameter before assigning to the variable/ output. You can update line 4 of your script to the following: outputs.objid = (jsonObj.devices[0].objid)? jsonObj.devices[0].objid.toString() : '';

Thanks for taking the time to understand even re-articulate it.  Much appreciated.

I added your line 4 and ran it, and find the same problem:

find_real_file.png

Even when there is no objid, there is still a response body, which is not being passed to the script step as an input variable to begin with.  The "Step Configuration" part of the script step should be passing that input variable whether there is an objid or not, as it does not even look for that until after the variable is received. 

In the case of this test, there is both a response body and an objid, so it makes a good demonstration of the problem.  (I think, let me know if I am missing something here of course).