Update records in a List Collector

danielbartholom
Mega Expert

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.

1 ACCEPTED SOLUTION

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

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

6 REPLIES 6

Hi @Ahmmed Ali ,

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?

Hello @danielbartholomew ,

 

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

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali