- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 02:45 AM
we have two variables in record producer one is country reference to country table and state referencing to state table. In country table we have list of countries and in state table we have country field referring to country table and state field having states based on country. In record producer once we select country, state should show in list based on country name. How to achieve this in service now
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 03:35 AM - edited 03-28-2024 03:41 AM
@VikramM1 Try the following, just change the table names according to yours.
Reference Qualifier in Catalog item:
Script Include:
var FilterStates = Class.create();
FilterStates.prototype = {
getStatesByCountry: function(country) {
//You check if the country is empty. If it is you don't include it in the reference qualifier and return.
if (!country) return '';
var stateList = [];
var stateGr = new GlideRecord('your_state_table');
stateGr.addQuery('your_country_field', country);
stateGr.query();
while (stateGr.next()) {
stateList.push(stateGr.getUniqueValue());
}
return "sys_idIN" + stateList.join(',');
},
type: 'FilterStates'
};
I hope this answers your question! 🙂
If it does, kindly mark it as answered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 03:35 AM - edited 03-28-2024 03:41 AM
@VikramM1 Try the following, just change the table names according to yours.
Reference Qualifier in Catalog item:
Script Include:
var FilterStates = Class.create();
FilterStates.prototype = {
getStatesByCountry: function(country) {
//You check if the country is empty. If it is you don't include it in the reference qualifier and return.
if (!country) return '';
var stateList = [];
var stateGr = new GlideRecord('your_state_table');
stateGr.addQuery('your_country_field', country);
stateGr.query();
while (stateGr.next()) {
stateList.push(stateGr.getUniqueValue());
}
return "sys_idIN" + stateList.join(',');
},
type: 'FilterStates'
};
I hope this answers your question! 🙂
If it does, kindly mark it as answered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 03:56 AM
Its didn't work still.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 03:59 AM
Could you please provide me with screenshots of your script include and reference qualifier? Please ensure that the names match your fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 03:13 AM
@VikramM1 Please use the below link as reference to your requirement to retrieve the values,
https://concurrency.com/blog/servicenow-dependent-variables-on-record-producer-in-service-catalog/
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 03:21 AM
This is for choice field