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

danielbartholom
Mega Expert

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();

}
}

 

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

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?

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

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

Thank you,
Ali