Read all the active directory attributes using LDAP query

Suresh1
Tera Guru

Hi Guys,

I am trying to read some attributes from active directory in ServiceNow using the LDAP query. using below query it will retrieve few attributes only (This is because in the LDAP server attributes we have mentioned around 5 Active directory attributes alone).

var distinguishedName='xyz'
var usrrec ='';
var ldapserver='xyz server;
var gr_LDAP = new GlideRecord('ldap_server_config');
if(gr_LDAP.get('name',ldapserver)){
var iniLdap = new GlideLDAP();
iniLdap.setConfigID(gr_LDAP.getValue('sys_id'));
iniLdap.setup();
var query = "(&(sAMAccountName=" + distinguishedName + "))";
var res = iniLdap.getMatching('', query, true, 10);
while(text=res.next()){
var usrrec = text.toString() + "";
}
}
gs.print(usrrec);

 

Right now we are getting samAccountName, DN, giveName etc. Now i want to also get the other attributes like phone, email, manager etc. from active directory. Please let me know how to get those attributes using this LDAP query apart from adding the LDAP server attributes.

 

PS: we don't have/using the orchestration, flow designer etc...

Thanks

1 ACCEPTED SOLUTION

Suresh1
Tera Guru

This is resolved,.. we have created a new LDAP server and have added the required attributes and then using the script, we are able to fetch the required attributes.

View solution in original post

8 REPLIES 8

Suresh1
Tera Guru

This is resolved,.. we have created a new LDAP server and have added the required attributes and then using the script, we are able to fetch the required attributes.

MGanon
Tera Guru

Which version is this?

Our Jakarta dies @ var iniLdap = new GlideLDAP();

MGanon
Tera Guru

I successfully queried an AD/LDAP record, or at least I think I did.

This section gave me errors:

while(text=res.next()){
var usrrec = text.toString() + "";

Retrieving with either "if(res.next())" or "while(res.next())" returned a Glide ldap.ldapresults record marker but I wasn't able to successfully extract specific fields.

I want to retrieve the memberof field from the AD/LDAP record.

Nicola Tomasell
Tera Contributor

Hi Suresh,

very interesting article .. 

I have to do a research in ldap but I use a Mid server to connect the ldap, is a way to this in the script?

I receive an error about this..

xxxxxx.zzzz.it:389
LDAP API - LDAPLogger : Communication error: xxxxxx.zzzz.it::389
LDAP API - LDAPLogger : java.net.NoRouteToHostException: No route to host (Host unreachable)
Evaluator: com.glide.script.RhinoEcmaError: Cannot convert null to an object.

thank you for your support
regards
NT