We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

BR to exclude some users from seeing some cases

ghitabahaj
Tera Expert

Hi everyone please i would like to write a BR to exclude exteranl users from seeing the offboarding case

 

GhitaB_0-1769161026340.png

GhitaB_1-1769161058666.png

 

here is the script but still didn t work

(function executeRule(current, previous) {

    var userId = gs.getUserID();
    gs.info('[HR VISIBILITY] Logged-in user sys_id = ' + userId);

    // Get HR Profile
    var hrProfile = new GlideRecord('sn_hr_core_profile');
    hrProfile.addQuery('user', userId);
    hrProfile.query();

    if (!hrProfile.next()) {
        gs.info('[HR VISIBILITY] No HR Profile found for user');
        return;
    }

    gs.info('[HR VISIBILITY] HR Profile found: ' + hrProfile.sys_id);

    // Country
    var country = hrProfile.u_legal_entity.u_country.getDisplayValue();
    gs.info('[HR VISIBILITY] Country = ' + country);

    if (country !== 'Spain') {
        gs.info('[HR VISIBILITY] User is NOT in Spain → exiting');
        return;
    }

    // Employment type
    var employmentType = (hrProfile.getValue('employment_type') || '').toLowerCase();
    gs.info('[HR VISIBILITY] Employment type = ' + employmentType);

    var excludedTypes = [
        '300000000123199',
        '300000000120757',
        'subcontractor'
    ];

    if (excludedTypes.indexOf(employmentType) === -1) {
        gs.info('[HR VISIBILITY] Employment type is NOT external → exiting');
        return;
    }

    gs.info('[HR VISIBILITY] Spain external user detected');

    // Exclude Offboarding
    current.addQuery('hr_service', '!=', '58d30358c3f4d2505c227e53e40131ed');
    gs.info('[HR VISIBILITY] Excluding Offboarding cases from query');

})();

 

1 ACCEPTED SOLUTION

Its_Azar
Mega Sage

Hi there @ghitabahaj 

 

why BR? can u try ACL

 

Use a Read ACL on sn_hr_le_case to deny access when:

HR Service = Offboarding

User is external (employment type / profile condition)

Or apply HR Criteria / User Criteria on the Offboarding HR Service

 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,
Azar
Serivenow Rising Star
Architect@ KPMG.

View solution in original post

5 REPLIES 5

Hi i actually ended up creating an ACL to deny access, cause none of the things i've did worked