Access control script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 05:33 AM
Hello,
I cant seem to get this script to work, what I'm trying to achieve is...
I've created a custom table called u_nda_register, on that table it holds fields u_project (referenced to: pm_project) and u_authorized_group (referenced to: sys_user_group)
What I want to happen is if a user goes to the pm_project table and the project matches one which is on the u_nda_register table and is part of the assignment group populated in u_authorized group they will be able to view the record. Otherwise it wont be visible.
(function() {
var ndagr = new GlideRecord('u_nda_register');
ndagr.addQuery('u_project', current.sys_id);
ndagr.query();
if (ndagr.next()) {
var authgroup = ndaRecord.u_authorized_group;
var graccess = gs.getUser().isMemberOf(authorizedGroup);
var userprj = gs.getUser().getPreference('current_project');
if (current.sys_id == userprj && graccess) {
answer = true;
return;
}
}
answer = false;
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 06:09 AM
Hi @Andrew_TND ,
Can you share the screenshot of your ACL, It should work. Which type of ACL have you written?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 06:14 AM
Hey Runjay
See below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 06:35 AM
Did you try adding gs.info() and check if it goes inside the query
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2024 06:35 AM
Hi @Andrew_TND ,
So you are checking role as well, if both satisfy then it will allow.
Also could you try without (function() {}.
Also run the code in background script and check whether it is going to correct if else or not.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------