The CreatorCon Call for Content is officially open! Get started here.

How to filter a reference variable through client script

Ak8977
Tera Expert

there were two variable called contractor and manager, contractor is of yes or no type. and manger is of reference type. if we select yes in the contractor then only the users whose mail id contains "@xyz.com" need to be shown in the manager field.

1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hello @Ak8977 

 

You just use Advanced reference qualifier on "Manager" variable like below & no need to write script include and client script : 

 

Note : Use your variable backend name wherever necessary

 

javascript: var query;
if(current.variables.contractor == 'Yes'){
 query = "emailLIKE@xyz.com";
}

 

VishalBirajdar_0-1695984383141.png

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

7 REPLIES 7

Harish KM
Kilo Patron
Kilo Patron

what happens to manager variable if we select "no" as contractor type?

Regards
Harish

if we select no it need to show all the users.

You can write a Script Include:

Script:

getUser: function() {
      var getContractor = current.variables.test_choice; // contractor variable type
      gs.info("s==="+getContractor );
// run only when contractor type is Yes
      if(getContractor == 'Yes'){
        var query = 'emailLIKE@xyz.com'; // email filter to query users
        var result = [];

        var user = new GlideRecord('sys_user');
        user.addEncodedQuery(query); // query to filter user
        user.query();
        while (user.next()) {
            result.push(user.sys_id);
            gs.info("user=="+result);
        }
        return 'sys_idIN' + result.join(','); // return users who have email
      }
     

    },
 
In your manager variable add the below reference qual. No need client script to filter
javascript:new ScriptIncludeName().functionName();
 
HarishKM_0-1695980021380.png

 

Regards
Harish

Vishal Birajdar
Giga Sage

Hello @Ak8977 

 

You just use Advanced reference qualifier on "Manager" variable like below & no need to write script include and client script : 

 

Note : Use your variable backend name wherever necessary

 

javascript: var query;
if(current.variables.contractor == 'Yes'){
 query = "emailLIKE@xyz.com";
}

 

VishalBirajdar_0-1695984383141.png

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates