BR to exclude some users from seeing some cases

GhitaB
Tera Contributor

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');

})();

 

2 REPLIES 2

vaishali231
Giga Guru

hey @GhitaB 

 

try this 

(function executeRule(current, previous) {

    var userId = gs.getUserID();

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

    if (!hrProfile.next()) {
        return;
    }

    // Country check
    if (!hrProfile.u_legal_entity || !hrProfile.u_legal_entity.u_country) {
        return;
    }

    var country = hrProfile.u_legal_entity.u_country.getDisplayValue();
    if (country !== 'Spain') {
        return;
    }

    // Employment type (sys_id comparison)
    var employmentTypeSysId = hrProfile.getValue('employment_type');

    var externalEmploymentTypes = [
        '300000000123199',
        '300000000120757'
    ];

    if (externalEmploymentTypes.indexOf(employmentTypeSysId) === -1) {
        return;
    }

    // Exclude Offboarding service
    current.addQuery('hr_service', '!=', '58d30358c3f4d2505c227e53e40131ed');

})();

 

*************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.

Regards
Vaishali Singh

Its_Azar
Kilo Sage

Hi there @GhitaB 

 

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,

Mohamed Azarudeen Z

Developer @ KPMG