We are using SharePoint online. would like to set a variable with user's ID.

The login name of the current user is returned as i:0#.f|membership|yourEmailadress.

Is there any way we can get the user id?

  • Are u using Workflow to get user_ID? Jun 19, 2017 at 10:03
  • I think you should clarify what you mean by 'set a variable' - is this in a workflow, or a page, or what? Jun 19, 2017 at 10:31
  • yes sharepoint designer workflow and am trying to set a field with user id
    – Rinu
    Jun 19, 2017 at 11:03
  • In that case see my answer below... it's a little bit long winded but it should work. Jun 19, 2017 at 11:35

2 Answers 2


I'm not sure if the ID is available in the same way in SPO as it is in on-prem, but logically I would use this approach:

  1. Have a script running on a PC somewhere that periodically (once a day should be enough) grabs a list of all users in the tenant - it's also a good idea when using a list like this to have it delete all the existing entries to avoid duplicates

  2. Script uploads the Claims-Based Auth username form and associated user ID to a list in SPO for each user it finds

  3. Workflow gets the ID by selecting the item from the list where it finds a match on the Claims-Based Auth username form


In Javascript:

var userID = _spPageContextInfo.userId; 

Update for workflows:

In workflows User profiles is available as a data source. Pick user profiles, ID and then match the list item so that Account name equals 'Created by' (as string)

  • If it's a page that's a nice elegant solution, but no dice if it's a workflow variable... hasn't been clarified tho. Jun 19, 2017 at 10:31
  • Sorry it is in a sharepoint designer workflow
    – Rinu
    Jun 19, 2017 at 11:05

Your Answer

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

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