I'm getting the error Object doesn't support property or method 'ExecuteOrDelayUntilScriptLoaded'.

Below is my code.

    SP.SOD.ExecuteOrDelayUntilScriptLoaded(getCurrentUser, "sp.js");

function getCurrentUser() {
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    currentUser = web.get_currentUser();
    context.executeQueryAsync(onSuccess, onFail);

function onSuccess(sender, args) {
    var acountname = currentUser.get_loginName(); // extract the login name from the account name

function onFail(sender, args) {
    alert('Failed to get current user' + args.get_message());
  • Can you please paste the full working code? even after enabling _spPageContextInfo, I am still getting error in the modern page. Thank you in advance. Commented May 11, 2020 at 15:50

2 Answers 2


Try to enable _spPageContextInfo option in Modern Script Editor Web Part: enter image description here

Then test again to see if it works:

enter image description here

enter image description here


Best and simple way to get current logged in user name is _spPageContextInfo.


_spPageContextInfo is a global variable usually available on any SharePoint page. This variable stores basic information about current web and current user.

Below are the Some examples:

  1. To Get User Display Name:

    var currentUserName=_spPageContextInfo.userDisplayName;

  2. To Get User Login Name:

    var currentUserLoginName=_spPageContextInfo.userLoginName;

  3. To Get User Id:

    var userID=_spPageContextInfo.userId

Reference: Get user logged on sharepoint online

  • Ganesh, I have already tried this but it didn't work. Commented May 6, 2019 at 14:26
  • Where are you trying to use this code? Commented May 6, 2019 at 16:50

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.