Reading LDAP for a single user and populating sys_user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2013 08:45 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2013 11:02 AM
When you set up LDAP integration, you should also set up a transform map on the Import Set table that is being written to when LDAP is queried.
The link below walks you through the process.
https://wiki.servicenow.com/index.php?title=LDAP_Integration_Setup
One thing to note, in order to update a record from clicking the button mentioned, you need to ensure whatever value is in the User ID field, the mapping from LDAP needs to also be the field that's being queried in the OU definition.
Example: If your User ID is the same as your LDAP samAccountName, the query field on your OU definition in the LDAP setup needs to be samAccountName. If this is not set up correctly, you should be seeing an error in the LDAP log when you click the button.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2017 10:17 AM
The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: LDAP Integration
Visit http://docs.servicenow.com for the latest product documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2019 12:59 PM
Did you ever get your script to work? I tried to recreate your script and it stopped returning here:
var result = ldap.getMatching('',query,true,10);
The result returned false with only "com.glide.sys.ldap.LDAPResult@[7 seemingly useless charaters]
Our version is Jakarta.