2

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.

1 Answer 1

3

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());
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.