- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 05:38 AM
Hello everyone,
I have a list collector on a catalog item. When the item is submitted the Values of the field on the RITM/SCTASK appear as "a, b, c". I've been asked to convert this format to "a | b | c". so basically the ask here is to remove the comma and insert a pipe. the script I have so far looks a bit like this
//Type appropriate comment here, and begin script below
var arr = g_form.getValue('compliance');
var list;
console.log(arr);
for(var i = 0; i <= arr.length; i++) {
list += arr[i] + " | ";
console.log(list);
}
g_form.setValue('comliance_test', list);
}
the problem I'm having is that the list comes back up undefined, and I also end up with an extra pipe added to the end of the string. any ideas?
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 08:32 AM
var list_comma = "abc,def,ghi";
var arr = list_comma.split(",");
var list_pipe = arr.join('|'); //join back with pipe
gs.print(list_comma);
gs.print(list_pipe);
/*
*** Script: abc,def,ghi
*** Script: abc|def|ghi
*/
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 08:21 AM
Tested example :
Output :
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 08:32 AM
var list_comma = "abc,def,ghi";
var arr = list_comma.split(",");
var list_pipe = arr.join('|'); //join back with pipe
gs.print(list_comma);
gs.print(list_pipe);
/*
*** Script: abc,def,ghi
*** Script: abc|def|ghi
*/
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2022 07:43 AM
This worked, thanks a bunch!