How to get one variable value from choice table dependent on another variable?

Sumer Sharma
Tera Contributor

Hi All,

I have created two variables on the record producer. Variable one name is country  and variable two name is state. Variable one is of choice type and variable two is a reference and is referring to choice table. Variable two is dependent on variable one, so if the country is selected in variable one then variable two should show only that states  based  on the country  and state value is coming from choice table. So how can we achieve this?

 

Thanks

4 REPLIES 4

SN_Learn
Kilo Patron
Kilo Patron

Hi @Sumer Sharma ,

 

Please check the below references:

Creating Dependent Variables in Service Catalog 

Dependent variable on Catalog item 

Dependent Select Box (Choice) Variables on Record Producers 

 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Shruti Khaire
Kilo Sage

Hello @Sumer Sharma,

 

This use case can be best fit for the display business rule. Can you tell me where you want to implement client side or the server side so that I can elaborate my answer more effectively.

 

Thank you!

Hi @Shruti Khaire,

I want this to implement on server side.

 

Thanks

Hello @Sumer Sharma,

 

You can try using script include shared below let me know if you need help.

 

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'
};

 

Thank you!