
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 12:20 AM
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
Solved! Go to Solution.
- Labels:
-
IntegrationHub

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2019 11:24 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 12:33 AM
Hi Suresh,
add those in the existing list with comma separated and it would fetch the new ones as well
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 04:04 AM
Hi Ankur,
We are using mid-server to connect to ldap server through ecc queue and we have defined ldap server and then ldap ou definition and using scheduled import to import user attributes in our system. But, I want to get attributes specific to a user by leveraging script only. But, when I tried the code snippet shared by Suresh, it showing connection time out issue.
Could you please help me on how to query AD from script to user attributes utilising mid-servers?
Thanks in advance!
BR,
Amish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 12:42 AM
Hi Ankur,
Thanks for the reply!!
We don't want to add the new ones in the attributes as because of some issues. is there any other way to get the new attributes apart from this way?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 12:51 AM
Hi Suresh,
If you are using AD and using LDAP Server for that; then I believe that is the only place which would tell ServiceNow which attributes to fetch from the AD out of the total
What are the issues you are referring here?
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader