- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-29-2018 10:53 AM
I have a choice list which is populated by a reference field, which has quite a lot of options.
I would like to be able to reduce the number of options based on the group membership of the logged in user.
Ex:
If I have 10 values populating this choice list, and a user who is a member of group X selects the dropdown, they will only see the first 5.
A user who is a member of group Y will only see the last 5 options.
A user who is a member of both groups will see all 10 options.
I believe I will need to use an On Load client script, but have not found a way to query for a group membership of the current user, and restrict (or show) the options accordingly.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-29-2018 12:58 PM
It will allow multiple group member values. This can be achieved.
g_scratchpad.memberCapex = true;
g_scratchpad.memberAdmin = true;
I haven't used the scratchpad much yet, am I able to define multiple results? In the BR you referred to g_scratchpad.member but the Client Script if statment just used g_scratchpad.-- Sorry for the typo it should be g_scratchpad.memberCapex = true; in the client script too
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-29-2018 12:58 PM
It will allow multiple group member values. This can be achieved.
g_scratchpad.memberCapex = true;
g_scratchpad.memberAdmin = true;
I haven't used the scratchpad much yet, am I able to define multiple results? In the BR you referred to g_scratchpad.member but the Client Script if statment just used g_scratchpad.-- Sorry for the typo it should be g_scratchpad.memberCapex = true; in the client script too
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-29-2018 01:37 PM
Thanks Prateek,
This helped me adjust the values of the choice list based on group membership, instead of needing to define a new role for each group.
Much appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-29-2018 12:16 PM
Prateek, thanks for that suggestion, I like the idea of using the groups specifically instead of needing to create roles to correspond to each group. This will be very helpful!
Steve, it seems to be half working after creating a role for testing on my logged in user. I have added an alert popup to confirm that my role membership is in fact true, however the g_form.removeOption line isn't working.
I suspect this is because the choice list is a reference field, and isn't just a static choice list. I tried using the sysID of the records, but that didn't work. Would I need to instead somehow adjust the reference qualifier on this field via the client script?
Thanks!
Ben

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-29-2018 12:57 PM
Sorry, I forgot that the admin role will always return true. I tried this to remove urgency 3 from my incident form with hasRoleExactly() and it worked for a pre-populated list.
If this doesn't work for you we can look at the possibility of it being from a reference table.
function onLoad()
{
var checkRole = g_user.hasRoleExactly('admin');
var choices = g_form.getValue('urgency');
if (checkRole == true)
{
g_form.removeOption('urgency', '3');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-29-2018 01:51 PM
Thanks Steve,
Your method of using roles worked after I ignored the "var choices" line and used the name of my field in reference with the sysID of the values on my reference list, shown below. Not sure why that line was giving me trouble.
Prateek's method with adding the business rule and making use of scratchpad values helped me do this without needing to define new roles, and can trigger changes based on my assignment groups on their own.
function onLoad()
{
var checkRole = g_user.hasRole('admin');
if (checkRole == true)
{
g_form.removeOption('u_portfolio', '7a2541fddbe7d780d93f591e5e96192c');
g_form.removeOption('u_portfolio', 'e55501fddbe7d780d93f591e5e9619ab');
g_form.removeOption('u_portfolio', '9b176ab3db816f00ceff3ebd7c96196c');
}
}