Error: Unexpected token in object literal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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"
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.
(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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Same error.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
please share the original json
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thanks for your help in this. As a workaround, we have decided to go with the transform function on the data pill.