Client Script - g_form.addOption() and g_form.removeOption()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2019 05:03 AM
I want to add an option 'Files' under choice list of 'Subcategory' field. But this option should be visible to only Service Desk group when they select 'Category' as Windows. Since there is a dependency, I am not able to get the value 'Flies' in 'Subcategory' using g_form.addOption() method.
If I am creating 'Files' under choices of 'Subcategory' making 'Windows' as dependent value then it will be visible to all. But my requirement is, it should be visible to only Service Desk group members. Even I am not able to remove that option using g_form.removeOption() method.
Any suggestions?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2019 05:40 AM
Can you provide your client script as removeOption and addOption should work. We have something similar where we remove all categories except specific ones when there is a specific assignment group selected.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2019 10:12 AM
Below is my script:
Business Rule:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if(gs.getUser().isMemberOf('Service Desk') || gs.getUser().isMemberOf('Service Desk L2'))
{
g_scratchpad.grp = true;
}
else
{
g_scratchpad.grp = false;
}
})(current, previous);
Client Script:
On change of Category.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var cat = g_form.getValue('category');
if(cat == 'Windows'){
g_form.addInfoMessage('inside cat loop');
if (g_scratchpad.grp==false)
g_form.addInfoMessage('inside scratchpad loop');
g_form.removeOption('subcategory','File/folder restore request');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2019 11:09 AM
Are you getting your info Messages and the g_form.removeOption is not working or are you not seeing that either?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2019 01:43 PM
Yes, I am getting info messages as expected. But choice option is not getting removed from the choices of sub category.
NOTE: As I observed, since 'File/folder restore request' is a having dependent value 'Windows' in choice of the Sub category field. Because of this, its not getting removed.
If I am removing dependent value then it is conflicting with my other users.