Reference field variables

Jude8
Tera Contributor

I have two reference field variables . They both point to same table . Variable A has 10 records , variable B options should be displayed based on selected choice in the variable A .

7 REPLIES 7

Sumanth16
Kilo Patron

Hi @Jude8 , 

 

Please refer to below thread:

https://www.servicenow.com/community/sysadmin-forum/show-specific-choices-based-on-another-field-cho...

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Thanks & Regards,

Sumanth Meda

Jude8
Tera Contributor

I have tried it but didnt work. I have created 2 custom tables and  i have two ref variables in catalog item. variable A refers to Custom table A , Variable B refers to custom table B . Custom table B has a reference field with custom table A. 

 

whenever variable A is selected , variable B should display choices based on var A. Can you help on this 

vishakhayadav24
Tera Guru

Hi @Jude8 

please try the below code and make modifications to your requirement

you can pass this ref qual in second variable

 

javascript: new scriptincludeName().YourFunctionName(current.variables.variable_a);

 

Script include:

 

 YourFunctionName: function(service) {  // service is your first selected variable-a

        var filterStr = '';

        var gr = new GlideRecord("your_table");

        gr.addQuery('field', service);

        gr.query();

        var pArray = [];

        while (gr.next()) {

            pArray.push(gr.fieldname.toString());

        }

        filterStr = 'sys_idIN' + pArray.toString();

        return filterStr;

    },