Skip to main content
Nintex Community Menu Bar

Issue on Nintex forms while working with JQuery to get Current User Department.

  • March 1, 2017
  • 6 replies
  • 47 views

Forum|alt.badge.img+2

we trying to get Current user Department from user profile properties , we have used below JS on Nintex forms and we are getting below error-

''  Uncaught ReferenceError: _spPageContextInfo is not defined ''

so we have tried same code which we have used in Nintex forms in Aspx page of SharePoint and we are able to get user properties of current user.

 

So we require your help in this case if you can check the JS code which we have used for Nintex , and guide us in achieving the output in Nintex forms.

below is the JS Code which we have tried :-

 

<script src="/Style%20Library/Js/jquery.SPServices-2013.02a.js" type="text/javascript"></script>

<script src="/Style%20Library/Js/jquery-1.11.1.js" type="text/javascript"></script>

 

<script type="text/javascript">

  var userid= _spPageContextInfo.userId;

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

  var requestHeaders = { "accept" : "application/json;odata=verbose" };

  $.ajax({

    url : requestUri,

    contentType : "application/json;odata=verbose",

    headers : requestHeaders,

    success : onSuccess,

    error : onError

  });

 

  function onSuccess(data, request){

      var loginName = data.d.LoginName;

    alert(loginName);

  }

 

  function onError(error) {

    alert("error");

  }

</script>

6 replies

Forum|alt.badge.img+14
  • Scholar
  • March 1, 2017

put your code without <script> tags into RegisterAfterReady event handler JavaScript events in Nintex Forms 

includes should be places into Form settings/Advanced/Custom JavaScript Includes


Forum|alt.badge.img+2
  • Author
  • March 2, 2017

HI Marian,

I have added my code in RegisterAfterReady as below;-

NWF.FormFiller.Events.RegisterAfterReady(function () {
var userId = _spPageContextInfo.WebAbsoluteUrl;
alert(userId);
});

but i am getting below error ;-

Regards,

Lalit Kasa


Forum|alt.badge.img+14
  • Scholar
  • March 2, 2017

try webAbsoluteUrl with lowercase 'w' wink.png


Forum|alt.badge.img+2
  • Author
  • March 2, 2017

Marian , Its still not working giving same issue . 

I am using below JS with mentioned code:-

jquery.SPServices-2013.02a.js
jquery-1.11.1.js

Can you advise if this JS is correct which i am using OR its required any other JS ?


Forum|alt.badge.img+14
  • Scholar
  • March 2, 2017

where have you placed your code, is it in form settings/custom javascript?

_spPageContextInfo shouldn't depend on any of these libraries.

you need not to load jquery library, there's already one loaded by nintex.

try investigate in developer console what's going on with _spPageContextInfo in your env.


Forum|alt.badge.img+9
  • Nintex Employee
  • March 15, 2017

Hi Lalit,

Aside from the embedded code you place in the Advanced > JavaScript section of Forms, how are you referencing the external libraries? Make sure you enter the references to the external libraries in the Form Settings > Advanced > Custom JavaScript Includes section without <script> tags and the url directly to the .js file:

Thank you,

Sean Fiene