Error: Unexpected token in object literal

Rajini2
Mega Sage

This is my Action script step, trying to use this in the flow whenever variables (special char escaped) need to be updated.  Now this is throwing an error when I am passing this value to variable "cable_installation_request_for_printer_selection_status"

 

Rajini2_0-1757103238580.png

Error:

{"cable_installation_request_for_printer_selection_status":"\"HP Inc DesignJet T1600 36" PostScript 3EK11A#B1K (HP Inc - 3EK11A#B1K) - \" : \"Complete\"","cable_installations_reviewed":"1"}

 

But, when I test the action separately, it is a success. you can see below how 36\" is escaped.

{"cable_installation_request_for_printer_selection_status":"\"HP Inc DesignJet T1600 36\" PostScript 3EK11A#B1K (HP Inc - 3EK11A#B1K) - \" : \"Complete\""}

 

Not sure how to fix this script. Need some help here.

Rajini2_1-1757103611125.png

 
(function execute(inputs, outputs) {    
    var variables = JSON.parse(inputs.variables);
    for (var key in variables) {
        var valueStr = variables[key].toString();
        var escapedValue = valueStr.replace(/"/g, '\\\"'); // Correct: escape double quotes
        var finalValue = JSON.stringify(escapedValue).slice(1, -1);
        inputs.ritm.variables[key] = finalValue;
    }
    inputs.ritm.update();
})(inputs, outputs);

 

9 REPLIES 9

Same error.

Rajini2_0-1757114519998.png

 

I would like to mention here, when I tried the Replace String transform function in the variable pill, it worked fine. But then the idea was to keep it inside the Action script that would address any variables anytime.

 

Github Copilot is suggesting this, but I don't know how to build this as I am not expert in flow actions.

Rajini2_1-1757114889144.png

 

please share the original json

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

Rajini2_0-1757115661668.png

The 1 -Lookup Record > ...> name value is 

HP Inc DesignJet T1600 36" PostScript 3EK11A#B1K (HP Inc - 3EK11A#B1K)

"HP Inc DesignJet T1600 36" PostScript 3EK11A#B1K (HP Inc - 3EK11A#B1K) - RITMXXXXXX" : "Complete"

Can you remove the double quotes and all spaces? Also, can you check if you can use the JSON builder action and use the JSON payload here?

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

Thanks for your help in this. As a workaround, we have decided to go with the transform function on the data pill.