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.