Script Include and List Collector Variable

danielbartholom
Mega Expert

Hi looking for some assistance please - Is this possible?:

I have a Cat Item with 2x fields on it

1) Assets - List Collector variable - Referencing alm_asset
2) Description - Multi Line variable

I have created the following Script Include:

find_real_file.png

 

On the Cat Item I have created the following Catalog Client Script

find_real_file.png

 Basically what this doing when you select an Asset on the cat item it is pulling back the display name and serial number to the Disposals field:

find_real_file.png

Is there a way I can edit my scripts so that if multiple assets are selected in the List Collector the display name and serial number will be displayed for each on a new line?

Any assistance would be most appreciated. Happy to share further information if required

Thanks

1 ACCEPTED SOLUTION

Hi,

 

Yes I am looking at it right now and this is exactly what I was after. I updated the code slightly and replaced the comma with \n so each new asset returns on a new line.

Thank you so much for looking into this for me and your full support through to resolution.

Dan

View solution in original post

25 REPLIES 25

Shweta KHAJAPUR
Tera Guru

Hi,

Can you modify below lines script include as below,

var arr [] ;

var app = this.getParameter('sysparm_app').split(",");

 

and 

 

gr.addEncodedQuery('sys_idIN'+app);

 in while loop,

while(){

arr.push('your_code');

}

return arr;

Hi,

 

Thank you for getting back to me on this. I am little confused where your above script lines needs to be amended. This is the full script include, could you kindly update for me so I can see where the changes need to be applied:

 

var getAssetDetails = Class.create();
getAssetDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getApp:function(){
var app = this.getParameter('sysparm_app');
var dis;
var gr = new GlideRecord('alm_asset'); //Replace cmdb_ci_appl with your table name
gr.addQuery('sys_id',app);
gr.query();
if(gr.next())
{
return gr.display_name + ' | ' + 'SN: ' + gr.serial_number; //Path should be replaced with you field which contains Path on technical system table
}
},
type: 'getAssetDetails'
});

Hi,

Try as Below,

var getAssetDetails = Class.create();
getAssetDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
getApp:function(){
var arr = [];
var app = this.getParameter('sysparm_app').split(',');
var dis;
var gr = new GlideRecord('alm_asset'); //Replace cmdb_ci_appl with your table name
gr.addQuery('sys_id','IN',app);
gr.query();
while(gr.next())
{
arr.push(gr.display_name + ' | ' + 'SN: ' + gr.serial_number); //Path should be replaced with you field which contains Path on technical system table
}

return JSON.stringify(arr);
}, 
type: 'getAssetDetails'
});

OK,

 

So I replaced your code with mine on the Script include. Now when a put Asset WMT000001 - PowerEdge R630 into the Asset(s) to dispose - working field I receive the following in the Disposal fields:

find_real_file.png

 

You will also notice to test I put in another Asset in the List Collector however this called nothing additional to the Disposals field

 

Does the script include need tweaking?