Friday, May 31, 2013

How to Ensure User using JavaScript Client Object Model

Hi Readers,

In Server Object Model, web.EnsureUser(loginName) checks whether the user is there in the sharepoint site and if not present , it automatically adds that user into the site.

Similarly using Client Object Model, Microsoft has introduced in same fashion using ECMA Client Object Model we can achieve same functionality.

In microsoft link below you might get to see this approach but if you try to use the same exact way it might not turn fruitful to you.
http://msdn.microsoft.com/en-us/library/ff408786(v=office.14).aspx

The reason why it is not working for you is only because you need to 'esureuser' on correct 'web' context.
i.e.  Try to initiate separate context for this command and then asyc the load objects.

 function EnsureUser(loginName) {
        var context = SP.ClientContext.get_current();
        siteObjects.currentUser = context.get_web().ensureUser(loginName);
       
        context.load(siteObjects.currentUser);
        context.executeQueryAsync(Function.createDelegate(null, ensureUserSucess), Function.createDelegate(null, ensureUserFailure));
    }

I hope this will be helpful

No comments:

Post a Comment