Not applicable

How to get current user details #JSOM, #O365, #jQuery, #Nintex forms

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. Is there any equivalent to this approach ? or else what is the best way to get user details?

Error: _spPageContextInfo is undefined

0 Kudos
Reply
4 Replies
janeyres
Nintex Newbie

Re: How to get current user details #JSOM, #O365, #jQuery, #Nintex forms

Hi,

This works, just tried it out. I did have to add the "language='javascript' type='text/javascript'" tags in otherwise it only ran in edit mode.

<script  language='javascript' type='text/javascript'  src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script  language='javascript' type='text/javascript' >
$(document).ready(function()
{
var userid = _spPageContextInfo.userId;
console.log("User = " + userid);

});
</script>

Jan

Reply
patrickabel
Automation Master
Automation Master

Re: How to get current user details #JSOM, #O365, #jQuery, #Nintex forms

Hello Prasad Madushanka​,

You shouldn't have any trouble using _spPageContextInfo within an O365 Nintex Form, but you might as a best practice consider polling for client context before performing any custom code. Here's an example on how you might do that:

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);

}

In your case, checking that the DOM is loaded will probably suffice, but this is my preferred approach especially when you're anticipating other custom SharePoint interactions (i.e. REST calls).

Thanks,

Patrick

Reply
maxime_ouellet
Forms Fledgling

Re: How to get current user details #JSOM, #O365, #jQuery, #Nintex forms

TypeError: "_spPageContextInfo is undefined"

  • onSPLoad https://*****.sharepoint.com/sites/*****-apps/teamsfactory/SiteAssets/js/NintexForms.js?rev=20190213.002:230
  • checkSPLoad https://*****.sharepoint.com/sites/*******-apps/teamsfactory/SiteAssets/js/NintexForms.js?rev=20190213.002:22

 

How did you success to load SPContext in a Nintex Form under SharePoint Online?

0 Kudos
Reply
maxime_ouellet
Forms Fledgling

Re: How to get current user details #JSOM, #O365, #jQuery, #Nintex forms

This script not working, so any suggestion to get SP Context in a Nintex Form for Sharepoint Online?

 

var pollSPInside;

NWF.FormFiller.Events.RegisterAfterReady(function () {

    console.log("*** pollSPInside form RegisterAfterReady: setInterval 500" );

    pollSPInside= setInterval(checkSPLoadInside, 500);

});

function checkSPLoadInside() {
    if (clientContext) {
        window.clearInterval(pollSPInside);
        onSPLoadInside();
    }

}
function onSPLoadInside() {
    try {
        console.log("*** onSPLoadInside called *** ");
        var userId = _spPageContextInfo.userId;
        console.log("*** onSPLoadInside  Current User = " + userId);
    }
    catch (err) {
        console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        console.log(err);
        console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    }
}

0 Kudos
Reply