1

How can I get Userid of a user based on his account name or email using SPServices

I checked here https://stackoverflow.com/questions/5542208/sharepoint-2010-use-spservices-to-get-a-users-id

but this is getting current user id I want to get userid of any user based on there account names.

1 Answer 1

1

For SharePoint 2010, you could use JSOM to load the user and retrieve user id by user.get_id()

ExecuteOrDelayUntilScriptLoaded(CustomFun, "sp.js");
        function CustomFun() {            
            var context = SP.ClientContext.get_current();
            var newUser = context.get_web().ensureUser("contoso\\usera");
            context.load(newUser);
            context.executeQueryAsync(function(){
                alert(newUser.get_id());
                alert(newUser.get_title());
            },
            function(sender, args){
                alert(args.get_message());
            });}

From SharePoint 2013, I would suggest you use REST api https://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html

3
  • I have SharePoint 2010
    – MJ X
    Commented Oct 3, 2018 at 6:04
  • 1
    Above script is tested in my local SharePoint 2010.
    – Lee
    Commented Oct 3, 2018 at 7:17
  • Nice worked for me
    – MJ X
    Commented Oct 3, 2018 at 9:29

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.