Populate reference variable options based on another choice datatype variable.

BanuMahalakshmi
Tera Contributor

Hi,

I want to populate reference variable value from the table starts with A depands on choice value.

 

if choice data type variable value - abc, then reference variable value displays the list of users name starts with A.

if choice data type variable value - cde, then reference variable value displays the list of users name starts with B.

Thanks.

 

 

1 ACCEPTED SOLUTION

swathisarang98
Giga Sage
Giga Sage

Hi @BanuMahalakshmi ,

 

You can create a reference qualifier and script include,

 

In the below i created a field with type Select box and based on choice returning the Users,

 

Reference qualifier:

swathisarang98_0-1719564022459.png

 

script include:

swathisarang98_1-1719564053310.png

var getUserNames = Class.create();
getUserNames.prototype = {
        initialize: function() {},

        getNames: function(check) {
            var arr = [];
            var gr = new GlideRecord('sys_user');
            if (check == 'choice1') //checking choice is abc
            {
                gr.addEncodedQuery('nameSTARTSWITHA');
            } else if (check == 'choice2') //checking choice is def 
			{
                gr.addEncodedQuery('nameSTARTSWITHb');
        }

        gr.query();
        while (gr.next()) {
            arr.push(gr.getValue('sys_id'));

        }
        return 'sys_idIN' + arr;

    },

    type: 'getUserNames'
};

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

View solution in original post

2 REPLIES 2

swathisarang98
Giga Sage
Giga Sage

Hi @BanuMahalakshmi ,

 

You can create a reference qualifier and script include,

 

In the below i created a field with type Select box and based on choice returning the Users,

 

Reference qualifier:

swathisarang98_0-1719564022459.png

 

script include:

swathisarang98_1-1719564053310.png

var getUserNames = Class.create();
getUserNames.prototype = {
        initialize: function() {},

        getNames: function(check) {
            var arr = [];
            var gr = new GlideRecord('sys_user');
            if (check == 'choice1') //checking choice is abc
            {
                gr.addEncodedQuery('nameSTARTSWITHA');
            } else if (check == 'choice2') //checking choice is def 
			{
                gr.addEncodedQuery('nameSTARTSWITHb');
        }

        gr.query();
        while (gr.next()) {
            arr.push(gr.getValue('sys_id'));

        }
        return 'sys_idIN' + arr;

    },

    type: 'getUserNames'
};

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

@BanuMahalakshmi

Thanks for marking my answer as helpful. If it helped you in any way please accept the solution so that it will be beneficial to the future readers with the same query.

 

Regards,

Swathi Sarang