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

Did you find a solution to this?

I am trying to do something similar.

the ldap.load function seems to do nothing,. =(

I opened a HI ticket.  Apparently the GlideLDAPUsers ldap.load() function (and the associated UI action) does not work if you are using a mid server.

https://hi.service-now.com/kb_view.do?sysparm_article=KB0621870

 

Can GlideLDAPUsers query by a different field? We need to query by employee_number corresponding to the LDAP employeeid field.

Martan
Kilo Explorer

sorry, duplicate post


Martan
Kilo Explorer

duplicate post