Reading LDAP in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2013 08:17 AM
I have a need to read an LDAP attribute (one that is not captured as part of our LDAP integration with sys_user) within a script. Is this possible and are there examples. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2013 11:16 PM
Here is the code, that you can use to get the user information from LDAP after passing the user id. Take the idea from here.
Also, If you are pre-calgary, Package calls will work. If you are on Calgary check this link and replace package calls:
http://wiki.servicenow.com/index.php?title=Packages_Call_Replacement_Script_Objects
var LDAPUtilCC = Class.create();
LDAPUtilCC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserGUID : function(userName){
var strUserId = new String(userName);
strUserId = strUserId.replaceAll(/[^a-zA-Z 0-9*]+/g,'');
return this._queryLDAP(strUserId);
},
_queryLDAP : function(strUserId){
var userGuid = "";
try{
var rec = new GlideRecord('ldap_server_config');
rec.get('fda9e90cac162c5e019dfeb9ffd9a3df');
var ldapc = new Packages.com.glide.sys.ldap.LDAPConfig(rec);
var ldap = new Packages.com.glide.sys.ldap.LDAP();
ldap.setConfig(ldapc);
var query = '';
if(!JSUtil.nil(strUserId)){
query = "(sAMAccountName=" + strUserId +")";
}
var result = ldap.getMatching('',query,true,1000);
if(!JSUtil.nil(result)){
while(test = result.next()){
var strResult = test.toString();
gs.log(strResult);
}
}
}catch{
gs.log("LDAPUtilCC: " + e);
}
return userGuid;
},
type : "LDAPUtilCC"
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2022 01:59 PM
9 years later, is there an updated version of this for Rome? I ran the package remover but the replacement script does not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2013 04:19 AM
Fantastic, thank you this will get me going!