Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Setting reference values based on checkbox selection

Vihar2
Tera Contributor

Hi All,

 

I have a requirement to set the reference field values based on the checkboxes selected. I have a catalog item with 4 checkboxes and a "Groups" reference variable, based on the checkboxes selected the Groups variable should show only the groups of particular type.

 

Ex: 1) Checkbox 1 selected - Groups variable should show  groups of "type 1"

2) Checkbox 1 and 2 selected - Groups variable should show  groups of "type 1" and "type 2"

Kindly, help me with the logic or code.

 

Thanks

1 REPLY 1

Rohit99
Mega Sage

Hi  @Vihar2,
You may try with following reference qualifier and script include

 

Script Include:

 

var GroupType = Class.create();
GroupType.prototype = {
    initialize: function() {
    },
    group:function(val1,val2)
    {
        var grp =[];
        var gr;
        if(val1=='true' && val2 =='false')
        {
            gr = new GlideRecord('sys_user_group');
            gr.addEncodedQuery('typeLIKE1cb8ab9bff500200158bffffffffff62');  // type 1 sys_id
            gr.query();
           
            while(gr.next())
            {
                grp.push(gr.getValue('sys_id'));
            }
            return 'sys_idIN' + grp;
        }
        else if(val1=='false' && val2 =='true')
        {
            gr = new GlideRecord('sys_user_group');
            gr.addEncodedQuery('typeLIKE74af88c6c611227d0066386e74dc853d'); // type 2 sys_id
            gr.query();
            while(gr.next())
            {
                grp.push(gr.getValue('sys_id'));
            }
            return 'sys_idIN' + grp;

        }
        else
        {
            gr = new GlideRecord('sys_user_group');
            gr.addEncodedQuery ('typeLIKE74af88c6c611227d0066386e74dc853d^ORtypeLIKE1cb8ab9bff500200158bffffffffff62'); // type 1 and type 2 sys_id
            gr.query();
            while(gr.next())
            {
                grp.push(gr.getValue('sys_id'));
            }
            return 'sys_idIN' + grp;

        }
    },
    type: 'GroupType'
};
 

ref qualifier :

 

javascript : new GroupType().group(current.variables.checkbox_01,current.variables.checkbox_02) // checkbox_01 & checkbox_02 are backend name of checkboxes.

Attaching screenshot for reference:

 

Rohit99_0-1725349113114.png

 

Rohit99_1-1725349154153.png

 

Rohit99_2-1725349203319.png

 

Rohit99_3-1725349276820.png

 

 

Please mark my response as correct and helpful if it helped solved your question.

 

Thanks,

Rohit Suryawanshi