Using the"Test" UI Action to pass in a JSON input is not working in the flow script to get the Object Value


Description

Steps to Reproduce

  1. Create a flow that accepts Input a JSON Object
  2. Use a script Step to log the jsonObject and its value using input.obj and input.obj.name
  3. The object appears as a String, And Value is Empty when logged in script Step.

Script Used is

outputs.JSONObj = inputs.obj;

Please see attached screenshots.

What syntax must be used to have an Input as JSON Object?

[{"name":"input1value"}]
{"name":"input1value"}
{name:"input1value"}

None of the formats work as the Object is not recognized as a JSON Object.

Cause

JSON field types are interpreted as a string on the ServiceNow platform.

Resolution

Use JSON.parse to convert a String into a JSON Object. See screenshot of the Parse Script Step:

How is the subflow working correctly when the Test Input is not accepting a JSON Object?

The subflow might be using an inline script. The variable json_obj is actually interpreted as an object in the engine, so it behaves as you expect it to.

Is the subflow that's converting the string into a JSON object which is then passed on to the action?

In the subflow, it's not a string but rather returns the object. This object is passed to the action.

Is it a bug with Workflow Action?

Technically the JSON input type is stored as a string on the platform.

The subflow is converting it into a JSON object before passing it to the action, which is why it works with the subflow and not the test action.