Removing choices using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 10:33 AM
Hello experts,
I have a use case as given below-
1. Field 1 - Customer: type a) Internal b) external
2. Field 2 - Location
Location choice - USA, UK, Germany
For b) external, show only UK and hide rest.
I think I cannot use UI policy. Trying my hands on Client Script, however I'm not doing it right.
Please suggest. Thanks!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 10:41 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 10:43 AM
Hi
UI policy might create conflict if you have 'None' option and not defaulting to either of one choice, so try below onchange client script and modify accordingly. Don't forgot to mark my answer as correct if that helps.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue == 'internal')
{
g_form.clearOptions('location');
g_form.addOption('location', 'choice value', 'choice label');
}
else if(newValue == 'external')
{
g_form.clearOptions('location');
g_form.addOption('location', 'choice value', 'choice label');
g_form.addOption('location', 'choice value', 'choice label');
}
else
{
g_form.clearOptions('location');
//add none
g_form.addOption('location', '--None--', '--None--');
}
//Type appropriate comment here, and begin script below
}
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 11:58 AM
Hi Musab,
Thanks for your response.
The customer information is a check-box. For eg. Customer - this field refers to company list.
There is a check-box for 'external' user. The field says, if customer not found, click here...
In this case, what should be the newValue?
if(newValue == 'internal')
Should it be if(newValue == 'true') as it's a checkbox?
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2022 11:45 PM
Hi
I will just give you hint, if you are confused about backend value then always try to show them as Alert in your case just add alert as
alert(newValue);
This will backend value of internal or external , also in case you want to know onload script then use like this.
alert(g_form.getValue('name of field');
Don't forgot to mark my answer as correct if that helps.
Regards,
Musab