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.

How to create the dependency choices on choice variable

vinod6
Tera Contributor

In catalog items I have created two variables

 

1. Company Name---Type is choices

  1. Company A

  2. Company B

  3. Company C

 

2. Location ------Type is choice

  1. Hyderabad

 2.Bangalore

 3.chennai

 4.Pune

 5 Mumbai

 6.Delhi

 

Q:  i have selected the Company Name A Then Location vales shown the Hyderabad and Pune 

 

Could you please help any one. 

5 REPLIES 5

ARUN MANOJ
Tera Contributor

Service_RNow
Mega Sage

Hi @vinod6 

please refer it will be helpful

https://www.servicenow.com/community/developer-forum/how-to-display-locations-based-on-company-in-ca...


Please mark reply as Helpful/Correct, if applicable. Thanks!

 

Dhananjay Pawar
Kilo Sage

Hi,

You can write onChange catalog client script on Company variable and try below logic

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   if(newValue=='Company A')
   {
        g_form.removeOption('location','City 3');// add city names which you want to remove for company A
   }
   else if(newValue=='Company B'){
    g_form.removeOption('location','City 1');// add city names which you want to remove for company B
    g_form.removeOption('location','City 2');// add city names which you want to remove for company B
   }
   
}

Thanks.

swathisarang98
Giga Sage

Hi @vinod6 ,

 

You can refer the below article ,

https://www.servicenow.com/community/developer-articles/creating-dependent-variables-in-service-cata... 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang