- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 12:28 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 02:13 PM
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 02:13 PM
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 02:24 PM
Perfect that did the trick Thanks Kristen!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 02:35 PM
You're welcome!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 01:02 PM
I do not think an onChange script will get you to where you need to be effeciently. others can weigh in.
I would think you would write a Script Include and then call that Script Include from your Reference Qualifier field. The Reference Qualifier will fire the script include automatically whenever there is a change.
So Step 1: Write a script include (named such as filterStockroom)
Step: Update the reference qualifier (right click field-->configure dictionary; advanced qualifier with something like javascript: filterStoclroom() )
Section 4.3.2.2 here has a pretty good example:
http://wiki.servicenow.com/index.php?title=Reference_Qualifiers#gsc.tab=0
(Beginning of the Script Include. But it is not complete)
function filterStockroom() {
var grpList = '';
var stockroom = current.u_stockroom; ///replace with your field
if(stockroom) {
var grp = new GlideRecord('<table assets are kept>');
grp.addQuery(<grp.stockroom>, stockroom)
grp.query();
while(grp.next()) {
grpList += (',' + grp.sys_id);
}
}
return 'sys_idIN' + grpList;
}
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 01:20 PM
Thanks Daniel, So you are saying that the advanced reference qualifier works whenever the value in the stockroom changes, my qualifer is defined on the asset reference field as thats the one that gets the data based on the value in the stockroom
