The CreatorCon Call for Content is officially open! Get started here.

Auto populate assets assigned to user

josmad
Tera Contributor

Hi All,

I want to auto populate "asset_tag" value from asset table(alm_hardware) for selected user "requested_for" in service request. Could you please provide me the sample code to achieve this.

Thanks in advance. 

 

1 ACCEPTED SOLUTION

Hi Josmad,

The field you are trying to set is a reference field right? or it is a string field.

If it is a reference field it can hold only 1 value

if it is a string field then do you want to populate all the asset tags with comma separated in that field.

If yes then update script as below

getDetails: function(){

var arr = [];

var sysId =this.getParameter('sysparm_sysId');

var gr = new GlideRecord('alm_hardware');

gr.addQuery('assigned_to', sysId);

gr.query();

while(gr.next()){

arr.push(gr.asset_tag.toString());

}

if(arr.length > 0)

return arr.toString();

else

return '';

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

21 REPLIES 21

Aruna13
Tera Contributor

@Ankur Bawiskar i have posted a new query, can you please help me out?

@Aruna13 

Did you tag me in the new question? I couldn't see anything.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader