Skip to main content
Nintex Community Menu Bar

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

  • Mar 1, 2017 12:04 PM UTC
  • 6 replies
  • 68 views
  • Translate All

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
  • Mar 1, 2017 2:26 PM UTC

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

Translate

Forum|alt.badge.img+2

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

Translate

Forum|alt.badge.img+14
  • Scholar
  • Mar 2, 2017 7:09 AM UTC

try webAbsoluteUrl with lowercase 'w' wink.png

Translate

Forum|alt.badge.img+2

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 ?

Translate

Forum|alt.badge.img+14
  • Scholar
  • Mar 2, 2017 7:41 AM UTC

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.

Translate

Forum|alt.badge.img+9
  • Nintex Employee
  • Mar 15, 2017 6:00 PM UTC

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

Translate