Show and make a field mandatory based on group membership
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2017 03:13 PM
Hey all,
I have a requirement to have a field on the incident form and have it mandatory only when the logged in user is part of a specific group. I have tried a client script, business rules and UI Policy's using both g_form and gs.isMemberOf but i cant get it working, Can anyone advise? I have used some the scripts on the community as well but again, i cant get it working.
Any hep is appreciated as always.
Regards

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2017 03:33 PM
you need to use Ajax functionality in client script
also, the use isMemberOf is a method in getUser object not Glide system Object
gs.getUser().isMemberOf('YOUR GROUP NAME OR SYSID'))
Here are some links that explain more about Ajax functionality
Ask the Expert: GlideAjax - TechNow Ep 33 - YouTube
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2017 10:20 PM
Hi steve David
As per your req you need to create a display Business rule and one client script. Display BR is to check whether user belongs to the group or not. You can pass the info from server to client with help of g_scratchpad
Now at client side based on this g_scratchpad value you can hide the related list.
Step 1: Create a display BR and place this group between function template in script box
- var portfolioGrp = current.portfolio.group; //assuming portfolio is the column name and group is the column name on the referenced table
- var gr = new GlideRecord('sys_user_grmember');
- gr.addQuery('group', portfolioGrp);
- gr.addQuery('user', gs.getUserID());
- gr.query();
- if(gr.next())
- {
- g_scratchpad.user = 'true';
- }
Step2: Create a OnLoad client script to hide related list.
- function onLoad() {
- //Type appropriate comment here, and begin script below
- if (g_scratchpad.user) //will hide the related list if user belongs to the group
- {
- g_form.setMandatory('Field name here',true);
- }
- }
Please go through my comments in script and adjust the column names wherever necessary.
I hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2017 10:41 PM
Hi David,
Please follow the below steps to get this configured:
1) Write a Display Business Rule on the Incident Table as shown below:
In the above Screen shot Replace the Group "CAB Approval" with your Group Name
2) Once the Business Rule has been configured Write an On Load Client Script On the Incident Table to make the field Mandate if the Logged in User is a part of the required Group as shown below:
In the Above screen shot Replace "description" with your required field Name. I have written this as an On Load Client Script Based on your Requirement you can also write an On Change Script also and check for the same Scratchpad Variable as I have done that in the screen shot above.
Hope this helps.mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2020 01:43 PM
This answer worked well for me. Thanks