Client script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
Hii
If service portal in location offshore select means automatic to select country in india and cities are selected Hyderabad, Bengaluru, Chennai to select in automatically how and what shill I do please explain
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi @RavikumarY ,
You can achieve this behavior using a Catalog Client Script (onChange) in ServiceNow.....
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
// Field names – replace with your actual variable names
var locFieldName = 'location';
var countryFieldName = 'country';
var cityFieldName = 'city';
// If location changed to "Offshore"
if (newValue === 'Offshore') {
// Set country to India
g_form.setValue(countryFieldName, 'India');
// Clear city options and add only specific ones
g_form.clearOptions(cityFieldName);
// Add cities
g_form.addOption(cityFieldName, 'Hyderabad', 'Hyderabad');
g_form.addOption(cityFieldName, 'Bengaluru', 'Bengaluru');
g_form.addOption(cityFieldName, 'Chennai', 'Chennai');
// Optionally set a default city (say Hyderabad)
g_form.setValue(cityFieldName, 'Hyderabad');
} else {
// If location is not offshore, maybe reset country & cities
// Reset country
g_form.setValue(countryFieldName, '');
// Clear city options and restore all city choices (if you have static list)
g_form.clearOptions(cityFieldName);
// Example of adding back all city options
// these should include the others that were removed earlier
g_form.addOption(cityFieldName, 'Hyderabad', 'Hyderabad');
g_form.addOption(cityFieldName, 'Bengaluru', 'Bengaluru');
g_form.addOption(cityFieldName, 'Chennai', 'Chennai');
g_form.addOption(cityFieldName, 'Mumbai', 'Mumbai');
g_form.addOption(cityFieldName, 'Delhi', 'Delhi');
// etc.
// Optionally set city to blank
g_form.setValue(cityFieldName, '');
}
}
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/