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.

Hiding an option in reference field based on another field

Ramel
Mega Guru

Hi Community,

 

I was trying to hide an option in a reference field based on the selection on another field but I can't seem to make it work. I have seen a couple of similar question here in community but the solution that works for them does not seem to work when I tried it.

Requirement: 

When country = Singapore, category shoould show Recruitment, all other countries should not show the Recruitment category.

 

My script Include:

var CategoryCheck = Class.create();
CategoryCheck.prototype = {
    initialize: function() {
    },
    checkCountry: function(country) {
        gs.info('Check Country' + country);
        if(country == 'f9955b451bec55500826cbf2164bcb88') {//Singapore
        return "u_available_forISNOTEMPTY";
        }
        else {
            return "u_available_forISNOTEMPTY^u_name!=Recruitment/Onboarding";
        }
    },
    type: 'CategoryCheck'
};
 
Then, I have added the reference qualifier in the category field: javascript:new CategoryCheck().checkCountry(current.variables.u_country);
 
Can someone help to advise what am I missing.
 
Thank you.

 

1 ACCEPTED SOLUTION

Hi @Ramel 

 

Ok lets do vice-versa...have a try once.

 

javascript: 

var query;

if (current.variables.u_country != 'SINGAPORE'){
query = "u_available_forISNOTEMPTY^u_name!=Recruitment/Onboarding";
        }
else {
query = "u_available_forISNOTEMPTY";
}

 

I have checked in my PDI its working as expected....!!

Vishal Birajdar
ServiceNow Developer

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

View solution in original post

10 REPLIES 10

@Ramel 

As you have selected Lookup value field = Name

We should use name of country instead sys_id

 

I have just tried in my PDI 

 

update reference qualifier on category field.

javascript: 

var query = "u_available_forISNOTEMPTY^u_name!=Recruitment/Onboarding";

if (current.variables.u_country == 'Name of Country'){

           query = "u_available_forISNOTEMPTY";

        }
 
 
Vishal Birajdar
ServiceNow Developer

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

Hi @Vishal Birajdar 

 

I have also tried the Name of Country instead of the sysID, it also did not work.

Ramel_0-1694746498386.png

 

Ramel_1-1694746529423.png

I also tried using the Name of Country with my original script include instead of the sysID, also did not work. Appreciate your assistance. 

 

Regards,

@Ramel 

 

Actually "return" in if condition will not work here...

 

so use below reference qualifier : 

 

javascript: 

var query = "u_available_forISNOTEMPTY^u_name!=Recruitment/Onboarding";

if (current.variables.u_country == 'Name of Country'){

           query = "u_available_forISNOTEMPTY";

        }

 

this will definitely work

Vishal Birajdar
ServiceNow Developer

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

Hi @Vishal Birajdar 

I have tried the new script, still did not work.

Ramel_0-1694748018474.png

 

Ramel_1-1694748034595.png

 

Selected Australia and still showing the recruitment category. I dont know what is missing.

 

Regards,

 

Hi @Ramel 

 

Ok lets do vice-versa...have a try once.

 

javascript: 

var query;

if (current.variables.u_country != 'SINGAPORE'){
query = "u_available_forISNOTEMPTY^u_name!=Recruitment/Onboarding";
        }
else {
query = "u_available_forISNOTEMPTY";
}

 

I have checked in my PDI its working as expected....!!

Vishal Birajdar
ServiceNow Developer

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