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 01:50 PM
The dependent value should not matter. Can you confirm the value of the subcategory you have in your code is correct. Also since if it truly has a / in it you may want to use double quotes instead of single quotes.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2019 03:23 PM
Yes, the value is correct. I did check on that couple of times and I don't think using single or double quotes matters in this.
Let me inform you one more thing. If I am using g_form.removeOption('priority',1) is working fine. Because it does not have any dependent value. But same thing is not working for subcategory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2019 05:01 AM
Try this then. Remove the depending value from the subcategory and then create an onload client script to remove the subcategory unless the category is windows and the user is a member of the group that is allowed to select it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2019 11:35 AM
Assuming you have written onchange on category field, try this code.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.addInfoMessage("Scratchpad value is "+g_scratchpad.grp+"--cat value is "+newValue);
if(newValue == '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 the comment as a correct answer and also helpful if it helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2019 01:45 PM
Hi Asifnoor,
Same result. Still that choice value is visible!