Auto-populate Assets in List Collector Based on Selected "Requested For" User in ServiceNow Catalog

Shreya Nagar Na
Tera Contributor

There are two variables on my catalog item: one for "Requested For" and another one is an "Asset" variable (List Collector, table reference: asset table). Once the "Requested For" is selected, the "Assigned Asset" of this "Requested For" will be auto-populated in the "Asset" field. Here is the code, but it's not working. Please review for any mistakes:

 

Script Include:

ShreyaNagarNa_0-1718117100331.png

 

Reference Qualifier :
ShreyaNagarNa_1-1718117194160.png

 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Shreya Nagar Na 

 

Requiremnt:Once the "Requested For" is selected, the "Assigned Asset" of this "Requested For" will be auto-populated in the "Asset" field

 

Solution: In order to Auto-poulate the asset field, you need to use an onChange Client script on "Requested For". Inside this script, you need to make a GlideAjax call (Make sure that GetAssetDetails is a client callable script include, currently it is server side script include as it is not extended from Object.extendsObject(AbstractAjaxProcessor). In the responseCallback you need to assign the sys_ids returned from the script include.

 

In your current implantation you are using a reference qualifier which acts as a filter when you try to chose records from the field but doesn't auto populate the values for you. 

View solution in original post

3 REPLIES 3

Zach Koch
Giga Sage
Giga Sage

Do you know if you are getting your value back to your client script? I would start with adding log statements to between line 12 and 13, with <gs.info('example text ' +  asset.join(','))> and confirm that you are returning the value you want. If you are, then it may be an issue of how you are setting the value in the client script, which you can use < alert(value)> to see what you have on the client side.

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Sandeep Rajput
Tera Patron
Tera Patron

@Shreya Nagar Na 

 

Requiremnt:Once the "Requested For" is selected, the "Assigned Asset" of this "Requested For" will be auto-populated in the "Asset" field

 

Solution: In order to Auto-poulate the asset field, you need to use an onChange Client script on "Requested For". Inside this script, you need to make a GlideAjax call (Make sure that GetAssetDetails is a client callable script include, currently it is server side script include as it is not extended from Object.extendsObject(AbstractAjaxProcessor). In the responseCallback you need to assign the sys_ids returned from the script include.

 

In your current implantation you are using a reference qualifier which acts as a filter when you try to chose records from the field but doesn't auto populate the values for you. 

The requirement needs to be completed using the reference qualifier and script include, not by an onChange client script. That's why I'm using a reference qualifier. I have already completed this requirement using a client script.