- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 04:45 PM
I have a flow created and I can get all the data in the description field but it is UGLY!
I need a way to remove all those extra characters.
Any suggestions?
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 07:05 PM - edited 10-03-2023 07:58 PM
Hi @Shawn1
As MRVS value is a stringified version of JSON object, what you can do is create a flow variable and store this value after replacing all the characters with the help of replaceAll string method in inline script.
Then you can use the flow variable to append to your description.
var str = fd_data._1__get_catalog_variables.storage; // Change this to your Get Catalog Variables step and the MRVS variable name
str = JSON.stringify(str);
str = str.replaceAll("[", "").replaceAll("{", "").replaceAll("}", "----").replaceAll("]", "").replaceAll('"',"");
return str;
Please mark my answer helpful and accept as solution if it helped you 👍✅
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 07:05 PM - edited 10-03-2023 07:58 PM
Hi @Shawn1
As MRVS value is a stringified version of JSON object, what you can do is create a flow variable and store this value after replacing all the characters with the help of replaceAll string method in inline script.
Then you can use the flow variable to append to your description.
var str = fd_data._1__get_catalog_variables.storage; // Change this to your Get Catalog Variables step and the MRVS variable name
str = JSON.stringify(str);
str = str.replaceAll("[", "").replaceAll("{", "").replaceAll("}", "----").replaceAll("]", "").replaceAll('"',"");
return str;
Please mark my answer helpful and accept as solution if it helped you 👍✅
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 07:55 PM
Not being able to see the whole thing and just the stringified output, I would take a stab at using a regular expression to remove the undesired characters before assigning it to the description field.
function replacer(keytext) {
if(keytext == ":")
return " : ";
else
return "";
}
//assuming the variable holding the data was an JSON object or array of objects
var obj = [{
"item_description":"Printer",
"item_type":"other",
"justification":"I need to print stuff",
"quantity":"1"
},{
"item_description": "",
"item_type":"laptop",
"justification":"need to compute",
"quantity":"1"
}];
//Stringify it by wrapping it using method from JSON and replace the unwanted characters using .replace string method and regex
...
gr.description = JSON.stringify(obj)..replace(/[\[\{\}\]":]/g, replacer ).split(",").join("\n");
/****output
item_description : Printer
item_type : other
justification : I need to print stuff
quantity : 1
item_description :
item_type : laptop
justification : need to compute
quantity : 1
*****/