- 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
‎01-20-2021 02:46 AM
Hi
You very kindly helped me many moons ago with this question and I was wondering if you could help me to expand it a little please? Happy to open a new question if required but for now here goes:
On my form I have a multi line variable called Serial Numbers
What I want to do is copy Serial Numbers into this variable like so:
123456
765432
and so
On submit I want to call the following script include script:
var getAssetDetails = Class.create();
getAssetDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApp:function(){
var arr = '';
var app = this.getParameter('sysparm_app');
var app2 = app.toString().split(',');
var gr = new GlideRecord('alm_asset'); //Replace cmdb_ci_appl with your table name
//gr.addEncodedQuery('sys_idIN'+app);
gr.addQuery('serial_number', app);
gr.query();
while(gr.next())
{
//arr.push(gr.display_name); //Path should be replaced with you field which contains Path on technical system table
arr=(gr.display_name+' | '+'SN: '+gr.serial_number+' | '+'Condition: '+gr.u_disposal_condition)+"\n"+arr;
//arr=(gr.display_name+' | '+' SN: ' +gr.serial_number)"\n"+arr;
}
return arr;
},
type: 'getAssetDetails'
});
Right now this works if I put one serial number in however how can I get it working if I put multiple serial numbers in on separate lines?
Hope this makes sense?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2021 05:25 AM
Hello
I assume you are sending comma separated serial numbers in sysparm_app attribute in GlideAjax.
in your script, I am find one error which is in query.
gr.addQuery('serial_number', app);
you are adding app which is string instead of the array.
try statement as
gr.addQuery('serial_number', app2);
which will return the records where serial number is present in app2 array.
Thank you,
Ali
Thank you,
Ali