Options should get populated on the basis of different Country

shubhi211
Tera Guru

Hi, there is new requirement for Catalog Item:

On the Basis of User's "Country" Field.

The options under "Salesforce Instance" should get populated.

 

For eg: Country= INDIA || Country1 || Country 2|| Country 3, Salesforce Instance = "Instance A, Instance B",

Country= USA || Country 4,  Salesforce Instance = "Instance C, Instance D, Instance E",

Country= UK , Salesforce Instance = "Instance F, Instance G", and so on

 

Total there are 10 countries

If you want to change the field variable please let me know what Variable field should be

Ask.png

1 ACCEPTED SOLUTION

shubhi211
Tera Guru

addOption(String fieldName, String choiceValue, String choiceLabel, Number choiceIndex);

 

fieldNameStringThe field name.
choiceValueStringThe value stored in the database.(BACKEND Value)
choiceLabelStringThe value displayed.
choiceIndexNumberOrder of the choice in the list.

 

Client Script

Type: OnChange
Variable name: country
 function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
 
var uCountry = g_form.getValue('country');
if (uCountry == 'India' || uCountry == 'Country1' || uCountry == 'Country2' || uCountry == 'Country3') {

g_form.addOption('salesforce_instance', 'InstanceA', 'InstanceA', 1);
g_form.addOption('salesforce_instance', 'InstanceB', 'InstanceB', 2);

g_form.removeOption('salesforce_instance', 'InstanceC');
g_form.removeOption('salesforce_instance', 'InstanceD');
g_form.removeOption('salesforce_instance', 'InstanceE');
g_form.removeOption('salesforce_instance', 'InstanceF');
g_form.removeOption('salesforce_instance', 'InstanceG');
}

if (uCountry == 'USA' || uCountry == 'Country4') {

g_form.addOption('salesforce_instance', 'InstanceC', 'InstanceC', 1);
g_form.addOption('salesforce_instance', 'InstanceD', 'InstanceD', 2);
g_form.addOption('salesforce_instance', 'InstanceE', 'InstanceE', 3);

g_form.removeOption('salesforce_instance', 'InstanceA');
g_form.removeOption('salesforce_instance', 'InstanceB');
g_form.removeOption('salesforce_instance', 'InstanceG');
}

if (uCountry == 'UK') {
g_form.addOption('salesforce_instance', 'InstanceF', 'InstanceF', 1);
g_form.addOption('salesforce_instance', 'InstanceG', 'InstanceG', 2);
g_form.removeOption('salesforce_instance', 'InstanceA');
g_form.removeOption('salesforce_instance', 'InstanceB');
g_form.removeOption('salesforce_instance', 'InstanceC');
g_form.removeOption('salesforce_instance', 'InstanceD');
g_form.removeOption('salesforce_instance', 'InstanceE');
}
}

}

View solution in original post

5 REPLIES 5

Mark Manders
Mega Patron

It looks to be a choice field. Can you just make it depended on the choice of the country field?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

But how to make it Depended? Like there is no table for Salesforce Instance. It will be helpful if you explain in detail. Thank you

Please check the links from SarthakKashyap


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Community Alums
Not applicable

Hi @shubhi211 ,

Please check below links this may help you 

https://concurrency.com/blog/servicenow-dependent-variables-on-record-producer-in-service-catalog/

https://pathwayscg.com/using-category-and-sub-category-on-record-producers/

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak