Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

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
Kilo 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
Developer @ KPMG.

View solution in original post

5 REPLIES 5

vaishali231
Tera Guru

hey @ghitabahaj 

 

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 @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
Developer @ KPMG.

Max Dore
ServiceNow Employee

Assuming this is to hide it from the Employee Center, I would not use a BR, I would use the My Request Filters module which is what it is for.

You may need to create a Dynamic Filter Option record.

vaishali231
Tera Guru

hey @ghitabahaj 

Hope you are doing well.

Did my previous reply answer your question?

 

If it was helpful, please mark it as correct ✓ and close the thread 🔒. This will help other readers find the solution more easily.

Regards,
Vaishali Singh