Access control script help

Andrew_TND
Mega Sage
Mega Sage

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;
})();
8 REPLIES 8

Hi @Andrew_TND ,

 

Can you share the screenshot of your ACL, It should work. Which type of ACL have you written?

 

Hey Runjay

See below 


Andrew_TND_0-1730902421234.png
Andrew_TND_1-1730902442812.png

 

@Andrew_TND 

Did you try adding gs.info() and check if it goes inside the query

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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

-------------------------------------------------------------------------