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

Vishal Birajdar
Giga Sage

Hello @Ramel 

 

Can you please let us know what is the type of "category" field..?

 I guess its reference field.

 

Instead of writing script include and all can you try this reference qualifier

 

javascript:

if (current.variables.u_country == 'sys id of Singapore'){

           return "u_available_forISNOTEMPTY";
        }
        else {
            return "u_available_forISNOTEMPTY^u_name!=Recruitment/Onboarding";
        }

 

 

Vishal Birajdar
ServiceNow Developer

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

Hi @Vishal Birajdar 

 

Thanks for the response.

 

Correct, category field is a reference field. While my country is a lookup select type.

I have tried adding the script in the reference qualifier instead of using the script include but also did not work.

 

Ramel_0-1694743306711.png

 

I can still see the recruitment in the option when location is not Singapore.

 

@Ramel 

 Is it catalog item..??

Also can you provide screenshot of "country" filed or variable form.

I want to see type specifications for that variable/field

 

Vishal Birajdar
ServiceNow Developer

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

Hi @Vishal Birajdar 

 

It is a record producer. Country field is a lookup select box. It is looking up the record in the core_country table and only showing specific list of countries as defined in the reference qualifier.

Ramel_1-1694744497836.png

 

 

Ramel_0-1694744400377.png

 Regards,