Get AD user object GUID using Client Object Model in Sharepoint
-
03-10-2020 - |
Question
I want to extract the objectguid
corresponding to a username from the AD using javascript in Sharepoint.
Is it possible?
I can get some properties like the current username by using SP.UserProfiles
, but I'm stuck at finding the objectguid.
Solution
I guess you mean ADGuid
property, if so then the following example demonstrates how to retrieve this property:
function getUserProperties(loginName) {
var deferred = $.Deferred();
var ctx = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(ctx);
var properties = peopleManager.getPropertiesFor(loginName);
ctx.load(properties);
ctx.executeQueryAsync(function() {
deferred.resolve(properties);
},
function(sender,args){
deferred.reject(sender, args);
});
return deferred.promise();
}
Usage
getUserProperties(loginName).then(printUserProfileProperties,logError);
function printUserProfileProperties(properties) {
var extProperies = properties.get_userProfileProperties();
console.log(extProperies['ADGuid']);
}
function logError(sender,args) {
console.log('An error occured: ' + args.get_message());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange