- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 08:13 AM
GOod Day
i have a requirement where i have no idea where to go.
I have a Request form where different users will use but i want to have certain fields/variable to display or set to read only base on the logged in user Group Membership.
ex. John Smith is apart of "Group A"
Jane Doe is apart of "Group B"
Group A users will only see start date field /variable and the end date field /variable is hidden or read only
While Group B will have the start date field /variable hidden or read only while the end date field /variable they can modify
how can i:
1) detect the logged in user if they are belonging to a specific group
2) using the IF Statement i can determine if they belong to the Group A or Group B (this is the easy part)
i just need to know if they belongs to the group in question or not
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 06:09 AM
i was able to figure it out with a onLoad client script looking for the role
here is my code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 09:02 AM
Hi @Peter Williams,
You can create a Business Rule to find out what group the logged-in user is part of and then use that information from the Business Rule in the client script to hide the variable or make it read-only.
https://www.servicenow.com/community/itsm-forum/how-to-check-the-logged-in-user-is-a-member-of-a-gro... - You can review this post for script reference.
If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 10:08 AM
this post doesnt really give that much details on how to do this in the BR nor in the Client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 10:27 AM
i created this but doesnt seem to work
getting js errors on the console
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 10:32 AM
Hi @Peter Williams ,
You can create business rule update below script.
var grpusr = current.assignment_group.getDisplayValue();
g_scratchpad.member = gs.getUser().isMemberOf(grpusr);
})(current, previous);
Next create a client script on your requirement like On Load or anything.
then in client side
place below script:
if(g_scratchpad.member == true) {
g_form.setReadOnly('startdate', true);
}
Do same for groupb as well.
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand