How to get SCCM to find active user

marcbowen
Tera Contributor

When the SCCM 2016 Computer Identity runs is there a way to have the user lookup function find the active user record?  We have multiple users with the same email address/ username and it is finding the incorrect value during the lookup. 

function setAssignedTo() {
var userName = source.u_username;
if (JSUtil.nil(userName))
return;

var x = userName.indexOf("\\");
if (x > -1)
userName = userName.substring(x + 1);

Any help would be appreciated

 

 

1 ACCEPTED SOLUTION

You need to customize the setAssignedTo() function in the transform map named SCCM 2016 Computer Identity. OOTB, that function is defined as:

function setAssignedTo() {
    var userName = source.u_username;
    if (JSUtil.nil(userName))
        return;

    var x = userName.indexOf("\\");
    if (x > -1)
        userName = userName.substring(x + 1);

    var nameField = gs.getProperty('glide.discovery.assigned_user_match_field', "user_name");
    target.assigned_to = GlideUser.getSysId(nameField, userName);
}

That script gets the sys_id of the user simply by looking up the user name value for the user_name field in the sys_user table. It does that with the line:

target.assigned_to = GlideUser.getSysId(nameField, userName);

You can change that line to be something like:

var ugr = GlideRecord("sys_user");
ugr.addQuery("user_name",userName);
ugr.addQuery("active",true);
ugr.query();
// I assume that the above will only return one user. If that assumption is wrong,
// add more conditions to the query so that only one user record is returned
if(ugr.next()) {
    // set the assigned_to field to the sys_id of the first (hopefully ONLY) record found above.
    target.assigned_to = ugr.sys_id;
}

Frank

Please mark this reply as Helpful and/or Correct.

View solution in original post

3 REPLIES 3

Frank Tate
Giga Guru
Giga Guru

Your question doesn't seem to have all of the details needed to assist you. Can you explain in more detail the problem that you're facing? The statement "we have multiple users with the same email address/username" is very worrying. How would the system determine the "correct" user if there are multiple users that appear to be indentical based on username and email?

Frank

There are records in the user table with the same email address/username, however there is only 1 active person at a time. The user record SCCM finds during the lookup most times in the inactive one.

You need to customize the setAssignedTo() function in the transform map named SCCM 2016 Computer Identity. OOTB, that function is defined as:

function setAssignedTo() {
    var userName = source.u_username;
    if (JSUtil.nil(userName))
        return;

    var x = userName.indexOf("\\");
    if (x > -1)
        userName = userName.substring(x + 1);

    var nameField = gs.getProperty('glide.discovery.assigned_user_match_field', "user_name");
    target.assigned_to = GlideUser.getSysId(nameField, userName);
}

That script gets the sys_id of the user simply by looking up the user name value for the user_name field in the sys_user table. It does that with the line:

target.assigned_to = GlideUser.getSysId(nameField, userName);

You can change that line to be something like:

var ugr = GlideRecord("sys_user");
ugr.addQuery("user_name",userName);
ugr.addQuery("active",true);
ugr.query();
// I assume that the above will only return one user. If that assumption is wrong,
// add more conditions to the query so that only one user record is returned
if(ugr.next()) {
    // set the assigned_to field to the sys_id of the first (hopefully ONLY) record found above.
    target.assigned_to = ugr.sys_id;
}

Frank

Please mark this reply as Helpful and/or Correct.