Reading LDAP for a single user and populating sys_user

Martan
Kilo Explorer

I'm attempting to do a single user update of the sys_user record. Click a button, it grabs the userid, does an LDAP query and then re-populates the sys_user record.

So far I have this as prototype code:



/* Query LDAP for a specific UserID */

var ldapServer = new GlideRecord("ldap_server_config");
ldapServer.addActiveQuery();
ldapServer.query();

while (ldapServer.next())
{
var ldap = new GlideLDAP();
ldap.setConfigID(ldapServer.getUniqueValue());
var env = ldap.setup();
var query = '';

var strUserId = "mfs7a";
var i;

query = "(sAMAccountName=" + strUserId +")";
var result = ldap.getMatching('',query,true,10);

while(test = result.next())
{
var longString = test.toString();
gs.print(longString);
}
}


Which works fine as far as getting the current record from LDAP. However, I'm at a loss on how to deal with the raw LDAP record. I could just brute force it, chop up the strings and insert them into the sys_user record but that seems very 'not service now'. Can I use a transform map or something similar here to just map the values into the user record? If so, how would I do that?

Martan

12 REPLIES 12

Marcus Fly
Tera Expert

Why not use the OOB button on a users record? The OOB code you can find in UI Actions on the user table, the UI Action is below

UI Action Name: Refresh from LDAP


var ldap = new GlideLDAPUsers();
ldap.load(current.user_name.toString());
action.setRedirectURL(current);
gs.addInfoMessage("Reload of LDAP data for " + current.name + " has been started");


This function doesn't do anything. No updates happen.


Can you clarify "No updates happen"?
Do you see the message that the update started or do you see an error message?
You can also check in the LDAP log to see if there are any errors thrown, but the issue of it not updating can be a number of things and we'll need more information to help determine the root cause.


Yes, I see the message. No, nothing ever happens. I am guessing that since nothing has changed on the LDAP side, no imports are done. Can I bypass that somehow? Where is that script at? I can't seem to find it.

I really don't care if nothing has changed in the LDAP record for that user, I want to over-write the sys_user record with the current data when I click that link. I have it working via the script above, for the most part (it doesn't do passwords for example) but the major values- name, phone, department, manager, are pulled and over-write the sys_user record. It is sort of a 'brute force' approach but it does work. I was wondering if there is a better way to do this?