lalitkasa88
Canvas Initiate

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

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>

0 Kudos
Reply
6 Replies
emha
Automation Master
Automation Master

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

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

Reply
lalitkasa88
Canvas Initiate

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

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

0 Kudos
Reply
emha
Automation Master
Automation Master

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

try webAbsoluteUrl with lowercase 'w'

0 Kudos
Reply
lalitkasa88
Canvas Initiate

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

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 ?

0 Kudos
Reply
emha
Automation Master
Automation Master

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

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.

Reply
sean_fiene
Design Canvas Artiste

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

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

0 Kudos
Reply