Flow Designer script step with JSON.parse(x) fails if x is a Name/Values input to the action


Description

The flow script step fails when JSON.parse is used on a Name/Values input to the action.

Flow Designer throws error: "Unexpected token in object literal,Detail: Unexpected token in object literal".

Steps to Reproduce

1. Create an action with an input of type Name/Values.

2. Add a script step with input named "parameter" and map the action input to the script step input.

3. Add an output to the script step named "variable".

4. Add the following script body:
(function execute(inputs, outputs) {
var x = JSON.parse(inputs.parameter);
outputs.variable = x['a'];
})(inputs, outputs);

5. Use the Test button to run the test with input "a", "123". This fails, as in ops view the script input variable appears as type Name/Values with value {\"a\":\"123\"}.

Workaround

This problem has been fixed. If you are able to upgrade, review the Fixed In section to determine the latest version with a permanent fix your instance can be upgraded to.

 

The workaround is to change in the output script:

JSON.parse(x)

to:

JSON.parse(JSON.parse('"' + x + '"'))

 

An alternative workaround, in the affected action in Flow Designer, is to change the input type from Name/Value to String. Save, Publish, and re-trigger the Flow calling the Action to test it.

NOTE: This changes the input box to String type and passing inputs from the main flow to the Action might be harder to configure. Recommended to first set the input type of Action to Name/Value type, save Action, configure the main flows that call this Action, then apply the workaround above.

 

A further workaround is the following:

1. Navigate to sys_hub_action_type_base table and locate record for the Action with the issue. Note the main snapshot id.

2. Go to sys_hub_step_instance table and find record with Action Sys ID = <main snapshot id from step 1>. Note the sys id of this record.

3. Navigate to sys_hub_step_ext_input table and find record with Model ID = <sys_id of sys_hub_step_instance from step 2>.

4. Change the Type from Name/Value to String.


Related Problem: PRB1499511