How to remove slash from array of string?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2023 04:49 AM - edited ‎08-28-2023 03:44 AM
Scenario: I am designing a Action in Flow designer where through scripting i need to pass some array of string value.
Issue: When i run the code in Background Script it gives proper output but when i use same code in Actions it doesn't.
Expected/Correct output format which i am getting in Background script:
"Key":"abc","Key":"def","Key":"ghi","Key":"jkl"
Wrong output format which i am getting in Action by using same script:
"\"Key\":\"01\"","\"Key\":\"02\""
Script used:
var arrStr =["abc","def","ghi","jkl"];
var i;
var arrObj = {"Key1":[]};
for(i=0; i<arrStr.length; i++)
{
var testRec ="\""+"Key"+"\":"+"\""+ arrStr[i]+"\"";
arrObj.Key1.push(testRec);
gs.log(testRec);
}
for (var key in arrObj)
gs.print("Key is: " + key + " and value is: " + arrObj[key]);
Can anyone help in this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2023 06:32 AM
Hi @vishalj ,
Where exactly you are printing that output from action ?
I tried in my PDI with the same code and it gives me the expected output only. Try to elaborate more so that I can try that on my PDI as well.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2023 07:15 AM - edited ‎08-26-2023 07:15 AM
Hi @vishalj,
Try replacing the line where you have slashes to:
var testRec ='"'+'MATDOC_ITEM'+'":'+'"'+ arrStr[i]+'"';
I get the same output in scripts background. Use single quotes for string values when you want double quotes in the value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2023 08:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2023 11:47 AM
Hi @vishalj,
Then try:
var testRec = "MATDOC_ITEM:"+ arrStr[i];
since both are strings, why enclose in quotes?