How to Dynamically Filter Address varible choices Based onname varible on SC Task Form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi Community,
I need help with a requirement in ServiceNow related to Catalog Variables and Catalog Tasks (sc_task).
I have a catalog item with two variable sets:
- Name Variable Set
- Contains a Select Box variable named Name.
- The available choices are A and B.
- Address Variable Set
- Contains a Select Box variable named Address.
Requirement:
I want to dynamically populate the Address variable choices based on the value selected in the Name variable.
The expected behavior is:
- If the user selects A in the Name variable, the Address variable should display only Aa and Ab.
- If the user selects B in the Name variable, the Address variable should display only Ba and Bb.
Expected Output:
NameAddress Choices
A | Aa, Ab |
B | Ba, Bb |
The main requirement is that this functionality should work on the Catalog Task (sc_task) form, where the fulfillment team works on the task.
My Questions:
- Can we achieve this using a Catalog Client Script with an onChange function?
- If the variables belong to separate variable sets, how can we dynamically update the Address variable choices based on the Name variable?
- Are Catalog Client Scripts supported in the variable editor on the sc_task form?
- If Catalog Client Scripts are not supported in this context, what is the recommended alternative?
I would appreciate it if someone could share a working solution or an example script for this scenario.
Thank you for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
yes onChange Catalog Client Script with Applies on Catalog task checkbox as True will work here
something like this
function onChange(control, oldValue, newValue, isLoading) {
// Clear existing Address options
g_form.clearOptions('address');
// Add a placeholder option
g_form.addOption('address', '', '-- Select --');
if (!newValue) {
return;
}
if (newValue == 'A') {
g_form.addOption('address', 'Aa', 'Aa');
g_form.addOption('address', 'Ab', 'Ab');
}
if (newValue == 'B') {
g_form.addOption('address', 'Ba', 'Ba');
g_form.addOption('address', 'Bb', 'Bb');
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Instead of trying to solve an issue by looking at the solution, why not move the variables into the same set? What's the reason for keeping them separated?
Is that because in other Items they are not needed together? If that's the case, why not create a new one with both, so you have the logic in there? It seems like a lot of trouble to just get one dependency working.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
