3

I am using JSOM in Nintex Forms 2013. My script includes are

/_layouts/15/sp.runtime.debug.js
/_layouts/15/sp.debug.js
/_layouts/1033/init.js
/_layouts/MicrosoftAjax.js
/_layouts/sp.core.js
/_layouts/sp.runtime.js
/SiteAssets/jquery.SPServices-2014.01.min.js

As you can see I am trying to be very sure that I am loading all the js files for JSOM. I have successfully gotten to the end of my code while Previewing the form. However, in practice using the Display/Edit/New Form have the exact same Error as the title.

NWF$(document).ready(function(){    
    NWF.FormFiller.Events.RegisterAfterReady(function (){  
       setTimeout(onSPLoad, 3000);
       /// Despite using all load script methods this was still necessary  
    }); 
});

function onQuerySucceeded(sender, args) { 
  /// all variables except for collListItem given very unique names to 
  /// prevent script clashing       
  var oolistItemInfo = '';        
  var oolistItemEnumerator = collListItem.getEnumerator();     
   while (oolistItemEnumerator.moveNext()) {
    var oooListItem = oolistItemEnumerator.get_current();
    oolistItemInfo += '\nID: ' + oooListItem.get_id() + 
    '\nDisplay name: ' + oooListItem.get_displayName();
    }    
  alert(oolistItemInfo.toString());
}
function onQueryFailed(sender, args) {    
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}  
function onSPLoad(){
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', beginJSOM);
 }
 function beginJSOM() {
     var ooclientContext = new SP.ClientContext.get_current();
     alert(ooclientContext.get_url());
     console.log(ooclientContext.get_web());
     var ooweb = ooclientContext.get_web();
     alert("web");
     var oolistcoll = ooweb.get_lists();
     alert("listcoll");
     var ooList = oolistcoll.getByTitle('LegacyPolicies');
     alert('LegacyPolicies loaded');
     var oocamlQuery = new SP.CamlQuery();
          oocamlQuery.set_viewXml('<View><Query><Where><Leq>' + 
        '<FieldRef Name=\'ID\'/><Value Type=\'Number\'>5</Value>' + 
        '</Leq></Where></Query><RowLimit>50</RowLimit></View>');
     alert("QueryReady");
     this.collListItem = ooList.getItems(oocamlQuery);
     alert("collListItem");
     ooclientContext.load(collListItem, 'Include(Id, DisplayName)');
     ooclientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
 }

This code errors after alert(ooclientContext.get_url); Running get_web(); will cause the crash, it happens anywhere between clientContext.get_current() and get_web(). The exact line in sp.runtime.js that has the issue is this.$1_0=SP.ClientRequest.get_nextSequenceId();if(d){a.$1X(this); it appears to loop a few times through this, and then throws the error. Sorry I am not an expert at debugging.

UPDATE

I wanted to provide an update... using the script includes, also caused an issue because I was using a different version of the files with SharePoints Ribbon Tools in View/Edit/Disp. The correct way to go about this based on the answer, is to have no includes. And keep the code as is. without the setTimeout function, and SP.SOD function, this did not work. You may need to increase the timeout based on your machines performance, I'm not sure which script hasn't loaded yet.

1

First of all, sp.js IS loaded when you execute your code, otherwise you will get a "undefined" error message when calling "SP.ClientContext.get_current()". So, SP.SOD works as expected and loads the sp.js asyncronous.

I investigated a bit, I think I found the place, where your error occurs. It seems to occcur in the function SP.ObjectPath in the "sp.runtime.js". As the variables are different named in my js-file, it seems to be the place, because the sequence they occur is the same like you mentioned (and i did not find any other place where code occurs that is comparable to that one you posted)

As i also got into Troubles with that generic names during last SharePoint-Update (they renamed some of the generic ones) I guess it is the following Problem:

SP.SOD loads the current sp.js, which defines the context. and then, somehow you use a "old" Version of the "sp.runtime.js" or at least of that function. Because the property which causes the error, is a property of the context-parameter of the SP.Object-Constructor), which is actually named "$1X_0"

  • Interesting mix of problems then, because Preview for Nintex was successful. Great find. Thank goodness there is a 2 day limit for marking your answer as correct, because clearly, yours is correct. – christopher clark Dec 9 '15 at 15:35
  • Just out of curiosity, did you also need to set a timeout for some other js files to load? – christopher clark Dec 9 '15 at 15:36
  • No, usually SP.SOD does his Job as expected, at least as Long as you use SharePoint-Default-js-files. If you use your own js-files, you should make them "SOD"-able, just copy the relevant parts out of the SharePoint-js-files – Leopold Lerch Dec 11 '15 at 7:23
1

Oh my god.

/_layouts/sp.js was not included in the Javascript includes. Apparently, this loads by default in the Preview for Nintex. HOWEVER!

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', beginJSOM);

Is worthless. because it still executes beginJSOM function regardless.

I think this post will be useful since I never saw anyone successfully get JSOM working in Nintex Forms.

0

As said in above thread, this issue looks due to reason of referring old Version of the "sp.runtime.js". this issue got resolved once we refer new version of respective files as below:

"../_layouts/15/sp.js" and "../_layouts/15/sp.runtime.js"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.