2

I have used following code on Nintex forms on SharePoint 2013 to get current user details,

var userid = _spPageContextInfo.userId;
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ");

but it does not work on O365 Nintex forms (Error: _spPageContextInfo is undefined). Is there any equivalent to this approach ? or else what is the best way to get user details? I have tried codes as below,

Sample 01:

SP.SOD.executeOrDelayUntilScriptLoaded(FormLoad(), 'SP.js'); 
function FormLoad()
{
     var userId = _spPageContextInfo.userId;  
     console.log("Current User = " + userId); 
}

Sample 02:

var pollSP;  
NWF.FormFiller.Events.RegisterAfterReady(function () {  
    pollSP = setInterval(checkSPLoad, 500);  
});  

function checkSPLoad() {  
    if (clientContext) {  
        window.clearInterval(pollSP);  
        onSPLoad();  
    }  
}  

function onSPLoad() {  
    var userId = _spPageContextInfo.userId;  
    console.log("Current User = " + userId);  
}  

Note:

  1. SharePoint online site url- "https://abc.sharepoint.com/dev"

  2. Url when the Nintex form is opened- "https://abc-1d0266265ca24d.sharepoint.com/dev/..."

These codes work on on-premise SharePoint 2013 NINTEX form. (it doesn't redirect to app site when the form is opened)

Prasad De Silva
  • 836
  • 1
  • 12
  • 22

1 Answers1

0

Try Sample 1 without the brackets after FromLoad on the first line:

SP.SOD.executeOrDelayUntilScriptLoaded(FormLoad, 'SP.js'); 
Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34