Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Auto populate reference field values based on another reference field

ncp
Mega Guru

All,

I have done a lot of search on the community and have not found an answer to what I'm looking for. There are many similar questions, but not what I'm looking for:

Scenario:

I have two reference fields StockRoom & Assets that are defined as catalog client variables task which is part of a workflow.

When someone picks the stockroom I want only the assets that are in that stockroom to show up in the assets reference field and then allowing them to pick that asset

When the stockroom changes I want the asset list also to change

So this is similar to many posts that I saw for advanced reference qualifiers, but I dont think advanced reference qualifiers work for an "onChange" correct?

I also saw a lot of mention about catalog "onChange" client script, but all those were referring to populating the second reference field with a specific value, I would like the functionality to see all the assets when the stockroom value changes, allowing the user to pick the asset for that stockroom

Has anyone done something similar?

Thanks

1 ACCEPTED SOLUTION

Rather than returning the string of sys_ids, why not return the filter like this:



return 'install_status=6^stockroom='+selected_stockroom+'^substatus=Available'; (You can always double check the filter language by going to the asset table, filter it how you want for a particular stockroom, status, substatus, then right click and choose copy query. You can paste that into your script include and then just replace the sys_id of the stockroom with your selected_stockroom).



Also, double check that the script include is client callable (checkbox on the form).


View solution in original post

10 REPLIES 10

Obah
Tera Contributor

I had the same requirement, a simple working solution to curate the Assets reference field to only search assets belonging to the stockroom selected in Stockroom reference field is by writing the following script in the reference qualifier of the asset variable. 

javascript:"stockroom="+current.variables.stockroom

 

Obah_0-1717881489351.png