I'm trying these two ways to get the user id.

   $(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(loadUser, "sp.js"); });

    function loadUser() {

        var ctx = new SP.ClientContext.get_current();
        this.web = ctx.get_web();
        this.currentUser = this.web.get_currentUser();
        ctx.executeQueryAsync(Function.createDelegate(this, this.asdasd), Function.createDelegate(this, this.qweqwe));

    function asdasd(sender, args) {
    function qweqwe(sender, args) {

And replacing the top line with this.

             $(document).ready(function () {
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', loadUser);

Sometimes it brings the id and sometimes not, can someone help me to make this work constantly?


Can you not use _spPageContextInfo? It has the current user ID built in:



  • thanks a lot! I didn't know you could do that! I found a lot of people that did the other way haha – uhcnamuf Mar 27 '17 at 20:16
  • Yeah, _spPageContextInfo is very very useful! – Dylan Cristy Mar 27 '17 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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