- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 01:59 AM
I have a variable "Action Required" which has two options: Add and Remove.
The requirement is: When we select Add, Option "New website access for CUI secure transfer" should be visible. And when we select Remove, that option should not be visible.
I wrote a client script, but When I am selecting Add, the option is showing.
When I am selecting Remove, The option is not showing.
But again when I am selecting Add, the option is still not showing unless I refresh the page. Kindly let me know how to fix this issue. Thanks.
Field Name: Type of Request
Backend value: dependent_field_1
I wrote the below OnChange Client Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 02:12 AM
can you try below script:
function onChange(control, oldValue, newValue, isLoading)
{
if (isLoading || newValue == '')
{
return;
}
if(newValue=="1"){
g_form.addOption('dependent_field_1','New website access for CUI secure transfer',"New website access for CUI secure transfer");
}
else
{
g_form.removeOption('dependent_field_1','New website access for CUI secure transfer');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 02:08 AM
Hi @Sohini Kar ,
This might be because of 'isLoading' which is evaluating to false
Please try this client script and test again
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue == '1') {
g_form.addOption('dependent_field_1', 'New website access for CUI secure transfer');
} else {
g_form.removeOption('dependent_field_1', 'New website access for CUI secure transfer');
}
}
If my answer has helped with your question, please mark it as correct and helpful
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 02:23 AM
Same issue:
When I am selecting Add, the option is showing.
When I am selecting Remove, The option is not showing.
But again when I am selecting Add, the option is not showing unless I refresh the page.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 02:27 AM
please use the correct syntax for addOption
you need to mention the choice label and choice value both
Removing or Disabling Choice List Options
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 02:12 AM
can you try below script:
function onChange(control, oldValue, newValue, isLoading)
{
if (isLoading || newValue == '')
{
return;
}
if(newValue=="1"){
g_form.addOption('dependent_field_1','New website access for CUI secure transfer',"New website access for CUI secure transfer");
}
else
{
g_form.removeOption('dependent_field_1','New website access for CUI secure transfer');
}
}