- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2018 09:14 AM
Guy's,
Can you please help me:
I have a list collector variable which is referencing the alm_asset table. What I am looking to do (via workflow) is when the request item is submitted the current.sys_id of the requested item is added to the field u_disposal_request_line for each record in the list collector. I am working with the Run script below (via workflow)
List Collector variable name is 'assets'
var myString = current.variables.assets.toString();
var mySplitResult = myString.split(",");
for (i = 0; i < mySplitResult.length; i++){
var taskCi = new GlideRecord("alm_asset");
taskCi.addQuery('display_name', current.variables.assets);
taskCi.query();
if(taskCi.next()){
taskCi.u_disposal_request_line = current.sys_id;
taskCi.update();
}
}
The above script should be querying the alm_asset table and find the records where the display name matches the ones listed in the list collector and update the u_disposal_request_line field for each record with the current.sys_id of the requested item. However I just can't get it working. Where am I going wring in the script above 😞
Any assistance would be most appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2018 09:23 AM
Below script would work.
var myString = current.variables.assets.toString();
var query = "sys_idIN"+myString;
var asset = new GlideRecord("alm_asset");
asset.addEncodedQuery(query);
asset.query();
while(asset.next()){
asset.u_disposal_request_line = current.sys_id;
asset.update();
}
Thanks,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2018 09:16 AM
Just updated the script slightly for better clarity:
var myString = current.variables.assets.toString();
var mySplitResult = myString.split(",");
for (i = 0; i < mySplitResult.length; i++){
var asset = new GlideRecord("alm_asset");
asset.addQuery('display_name', current.variables.assets);
asset.query();
if(asset.next()){
asset.u_disposal_request_line = current.sys_id;
asset.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2018 09:23 AM
Below script would work.
var myString = current.variables.assets.toString();
var query = "sys_idIN"+myString;
var asset = new GlideRecord("alm_asset");
asset.addEncodedQuery(query);
asset.query();
while(asset.next()){
asset.u_disposal_request_line = current.sys_id;
asset.update();
}
Thanks,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2018 09:29 AM
A true Wizard my friend.
So to confirm (just so I understand)
var query = "sys_idIN"+myString; - This is querying the Sys_Ids of the individual records within the List Collector
asset.addEncodedQuery(query); - This is referencing the var query above?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2018 09:33 AM
Glad to know it helped.
Yes. In list collector, sys_ids will be stored with comma separated for all records selected. so we can use the same thing in query.
basically var query = "sys_idIN"+myString; -this is the query stating bring all records which matches the sys_ids passed. then pass the same to GlideRecord object as encoded query.
Thanks,
Ali
Thank you,
Ali