How to hide dropdown options depending on condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 07:38 AM
Hi all,
I need to hide request state field options for non-admin users on conditions.
If request state not 'approved', hide 'approved' and 'rejected'.
If rrequest state is 'pending approval', hide 'close_complete'
Help needed with the scripting please.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 07:48 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 07:52 AM
you should try with onChange() client script on state field.
Sample script. make sure you have mentioned the correct state value .
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// if (isLoading || newValue === '') {
// return;
// }
//Type appropriate comment here, and begin script below
if(!(g_user.hasRole('admin')) && (g_form.getValue('state') != 'approved'))
{
g_form.addOption('state','close_complete','Close Complete');
g_form.removeOption('state','approved');
g_form.removeOption('state','rejected');
}
else if(!(g_user.hasRole('admin')) && (g_form.getValue('state') != 'pending approval'))
{
g_form.removeOption('state','close_complete');
g_form.addOption('state','approved','Approved');
g_form.addOption('state','rejected','Rejected');
}
}
please refer the below doc links for more information about the glide form function and g_user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2018 02:11 AM
Hi Harshvardhan,
1. I don't want anyone (except admin) to be able to change state at any stage ie:before 'onChange' also.(if the state is 'draft', approved and rejected should be hidden). Should I use 'onLoad'?
2. In the second half of the script, my requirement is when the state is 'pending approval', approved and rejected should be visible and close_complete should be hidden.
else if(!(g_user.hasRole('admin')) && (g_form.getValue('state') != 'pending approval'))
When I changed the condition state=='pending approval', approved and rejected are still hidden.
Could you please help me getting it right.
Thank you