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.

Advanced reference Qualifier in ServiceNow based on other choice field.

surendra Gelivi
Tera Contributor

I have a requirement like their is two fields one is choice and another is reference. based on choice field selection the reference field values should change.
example: choice field have A,B,C .  if A is selects the reference field should show only few options.

if B is selects the reference field should show only few other options.


i used advanced reference qualifier : new Reference_field_validate().getUsers(current.request_type);
script include like : 

var Reference_field_validate = Class.create();
Reference_field_validate.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getUsers: function(request_type) {
       
        var reqType = request_type;
        var Equery = "";
        var gr = new GlideRecord('sys_user');
       
        if (reqType == 'A') {

            Equery = 'u_levelINSr Director,Managing Director,Partner,Principal,Income Partner';
           
        }
        gr.addEncodedQuery(Equery);
        gr.query();
        var users = [];
        while (gr.next()) {
            users.push(gr.getUniqueValue());
            // users.push(gr.getValue('sys_id'));
        }
        // return users.join(',');
        return "sys_idIN" + users;
    },

    type: 'Reference_field_validate'
});

Any one can help me regarding this.
1 ACCEPTED SOLUTION

Appanna M
Tera Guru

Hello @surendra Gelivi ,

There is a syntax error (current.variables.request_type you should pass a parameter) in your reference qualifier please correct it like below:

Syntax of advanced reference qualifier:- javascript: new Reference_field_validate().getUsers(current.variables.request_type);

 

I have created a similar case in my PDI it's working fine. Can you try applying the same. My case the filter condition is applying with title.

Note: Go and create a new script include and make sure check the client callable option. 

You can try update your function code like below once. 

 

 

getUsers: function(request_type) {
        var Equery;
		var users = [];
		gs.info("ReqType:"+request_type); // To check the value is coming or not
        if (request_type == 'A') {
            Equery = 'u_levelINSr Director,Managing Director,Partner,Principal,Income Partner'; // Check the backend value for level.
        }else{
			Equery = '';
		}
		var gr = new GlideRecord('sys_user');
        gr.addEncodedQuery(Equery);
        gr.query();
        while (gr.next()) {
            users.push(gr.sys_id.toString());
        }
        gs.info("User List:"+users);
        return 'sys_idIN' + users;
    },

 

 

Below are the ref screenshots:

Appanna_0-1711997547163.png

 

Appanna_1-1711997571029.pngAppanna_2-1711997620862.pngAppanna_3-1711997678137.pngAppanna_4-1711997707206.png

Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.

 

View solution in original post

5 REPLIES 5

Appanna M
Tera Guru

Hello @surendra Gelivi ,

 

Please Mark My Answer as Helpful.

 

Regards,

Appanna.