- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 09:52 AM
Hi all,
I'm trying to extract Sys IDs from a List Collector variable in a ServiceNow workflow script and then use those sys id to glide into the record to get particular values. The same code works fine in Background Scripts, but in the workflow it does not work
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 10:28 AM
It's likely running into a problem trying to execute a string method (split) on a value that is not interpreted as a string, so try something more like this - in the context of whatever makes sense in the entire script - to force the list collector variable value to a string before splitting it:
var sysIdArray = current.variables.sysregion.toString().split(',');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 10:18 AM - edited 12-12-2024 11:24 AM
Hi @RanjanRP,
Please share the code screen shot which you added in workflow.
The code will work on background, if you explictly added sys_ids' with comma seperated values.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 10:28 AM
It's likely running into a problem trying to execute a string method (split) on a value that is not interpreted as a string, so try something more like this - in the context of whatever makes sense in the entire script - to force the list collector variable value to a string before splitting it:
var sysIdArray = current.variables.sysregion.toString().split(',');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 10:40 AM
below is the code am using
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 10:49 AM
In addition to forcing to string, only use the initialize() method when creating a new record, and you don't even need/want an array in this case - just use the comma-separated list of sys_ids that is the list collector value:
var sysregion = current.variables.please_select_all_of_the_regions_that_apply.toString(); //list collector
var resultsArray = [];
var gr = new GlideRecord('u_req_lookups');
gr.addQuery('sys_id', 'IN', sysregion);
gr.query();
while (gr.next()) {
resultsArray.push(gr.u_dependantvalue1.toString());
}
var regionsString = resultsArray.join(', ');
current.variables.selectedregions = regionsString;