SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can you get the current users id using javascript? Can you do this any JS file or does it need to be added at a certain point?

share|improve this question
up vote 3 down vote accepted

My favorite is to use the SPServices jQuery library, specifically the GetCurrentuser operation.

share|improve this answer

Since you are working on 2010 version you can use Client Object Model to get current user (and some other cool stuff).

Here is link to simple example:


<script type="text/javascript">
    ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js");
    var context = null;
    var web = null;
    var currentUser = null;

    function getWebUserData() {
        context = new SP.ClientContext.get_current();
        web = context.get_web();
        currentUser = web.get_currentUser();
        context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), 
             Function.createDelegate(this, this.onFailureMethod));

    function onSuccessMethod(sender, args) {
        var userObject = web.get_currentUser();
        alert('User name:' + userObject.get_title() + '\n Login Name:' + 

    function onFailureMethod(sender, args) {
        alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
share|improve this answer

Just wanted to share: If you are looking for the ID of the current user only, there is no need to use any framework or API - SharePoint (at least in 2010, don't know in other versions) saves the ID in a global javascript variable named '_spUserId'.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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