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 Commented Oct 3, 2018 at 6:04
  • 1
    Above script is tested in my local SharePoint 2010. Commented Oct 3, 2018 at 7:17
  • Nice worked for me Commented Oct 3, 2018 at 9:29

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.