How to Filter Users with HR Profiles

pjftenorio
Giga Guru

Hi, I've already created an Advance Reference Qualifier in Variable Set for Opened For/ Subject Person referenced to table [sys_user] and to filter only users with HR Profiles but since this is a query, loading of users in drop down takes 3-5 seconds before showing and it is a bad user experience.

 

Is there any way to optimize it?

 

Variable setup:

pjftenorio_0-1759423652488.png

 

Script Include:

var NMHRProfileUtils = Class.create();
NMHRProfileUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

	initialize: function() {},

    getListUsersWithHRProfile: function() {
        var ids = [];
        var gr = new GlideRecord('sn_hr_core_profile');
        gr.addNotNullQuery('user');
        gr.query();
        while (gr.next()) {
            ids.push(gr.getValue('user'));
        }
        if (ids.length === 0) {
            return 'sys_id=NULL';
        }
        return 'sys_idIN' + ids.join(',');
    },

    type: 'NMHRProfileUtils'
});

 

1 ACCEPTED SOLUTION

Updating my reply. It works now

 

Here is the setup that we've come up in the variable under variable set.

pjftenorio_0-1759489131862.png

 

Then in script on record producer, we use the dot-walk as @palanikumar had mentioned.

pjftenorio_1-1759489196081.png

 

 

View solution in original post

7 REPLIES 7

palanikumar
Giga Sage
Giga Sage

Hi,

The script you have created will return all the user having HR Profile which causes the performance issue.

Can you create reference for HR Profile record instead? From your flow you can get the User record using dot walking.

 

Thank you,
Palani

Hi @pjftenorio 

Yes — that suggestion is absolutely correct and will greatly improve performance.

You're currently referencing the sys_user table and filtering it by querying sn_hr_core_profile, which is expensive.

Instead, reversing the logic — referencing HR Profile (sn_hr_core_profile) directly, and then dot-walking to the user — is both simpler and much faster.

Thanks,
Vignesh
"If this solution resolves your issue, kindly mark it as correct."

 

Updating my reply. It works now

 

Here is the setup that we've come up in the variable under variable set.

pjftenorio_0-1759489131862.png

 

Then in script on record producer, we use the dot-walk as you had mentioned.

pjftenorio_1-1759489196081.png

 

 

Hi @pjftenorio ,

Nice to see that my suggestion helps you. You can also add condition in reference qualifier condition to check if user.active is true to avoid inactive users being listed.

 

Please mark my response as correct solution if it solves your issue.

 

 

Thank you,
Palani