logo

NJP

Find User records which do not have an HR Profile record.

Import · Feb 07, 2019 · article

I was wondering how many user records in my instance did not have a corresponding HR Profile record created. I couldn't seem to find this elsewhere on the community, so I figured I'd share.

Running a fix script similar to what is written below should print out an info level log message for each User sys_id which does not have a corresponding HR Profile record (yet).

var userGR = new GlideRecord('sys_user');
//userGR.setLimit(100);
userGR.query();

var missingHR = [];
var userIDs = [];

while(userGR.next()){
    var hasProfile = new sn_hr_core.hr_Profile(userGR, gs).userHasProfile(userGR.sys_id);
    if(hasProfile){
        userIDs.push(userGR.getValue('sys_id'));
    } else {
        missingHR.push(userGR.getValue('sys_id'));
    }
}

//gs.info('KMB: userID ' + userIDs[0]);
for(var i = 0; i < missingHR.length; i++){
    gs.info('KMB: missingHR ' + missingHR[i]);
}

image

*this works in the following version

Build name: LondonBuild date: 12-20-2018_1717

Build tag: glide-london-06-27-2018__patch4-hotfix2-12-20-2018

View original source

https://www.servicenow.com/community/hrsd-articles/find-user-records-which-do-not-have-an-hr-profile-record/ta-p/2314683