- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 06:22 AM
Hi All,
I am trying to write ACL on glide list type field but it is not working as expected.
Can someone please help me
answer = gs.getUser().isMemberOf(current.field_name);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 12:07 AM
Hi @sonu9
you are on the right path by trying to check if the current user is a member of the list stored in that Glide List field, but when you are dealing with Glide List fields, especially those referencing the sys_user table, you will often need to manually parse the list and then check if the current user’s sys_id is one of those in the list. The isMemberOf method won’t directly work in this case because it’s typically used for checking group memberships, not Glide List fields.
//assuming the Glide List field is storing sys_ids from the sys_user table:
var currentUserId = gs.getUserID();
// Get the value of the Glide List field (a comma-separated string of sys_ids)
var glideListValue = "" + current.field_name; // Ensure it’s treated as a string
var userIds = glideListValue.split(",");
// Check if the current user’s sys_id is in the array
var userIsInList = userIds.indexOf(currentUserId) !== -1;
answer = userIsInList;
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 10:15 PM
Hi @sonu9
When writing ACLs (Access Control Lists) for Glide List type fields in ServiceNow, it’s important to understand how Glide Lists function and the correct methods to use in your conditions to reference them. If your ACL is not working as expected, it might be due to how you’re referencing the Glide List field or a misunderstanding of how isMemberOf works.
The isMemberOf method is typically used with the GlideUser (accessible through gs.getUser()) to check whether the current user is a member of a specified group. Glide List fields hold references to other records (like sys_id values of user group records in your case), and directly comparing or checking membership via isMemberOf using the field name as a string won’t work as expected. The isMemberOf function expects a group name (string) as its argument but providing it a field name (current.field_name) doesn’t directly provide the names or sys_ids of the groups in the Glide List.
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 11:55 PM
Hi Deepak,
Glide list field referencing user(sys_user table) table, please suggest me correct approach to achieve the functionality.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 12:07 AM
Hi @sonu9
you are on the right path by trying to check if the current user is a member of the list stored in that Glide List field, but when you are dealing with Glide List fields, especially those referencing the sys_user table, you will often need to manually parse the list and then check if the current user’s sys_id is one of those in the list. The isMemberOf method won’t directly work in this case because it’s typically used for checking group memberships, not Glide List fields.
//assuming the Glide List field is storing sys_ids from the sys_user table:
var currentUserId = gs.getUserID();
// Get the value of the Glide List field (a comma-separated string of sys_ids)
var glideListValue = "" + current.field_name; // Ensure it’s treated as a string
var userIds = glideListValue.split(",");
// Check if the current user’s sys_id is in the array
var userIsInList = userIds.indexOf(currentUserId) !== -1;
answer = userIsInList;
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma