Using Javascript Object Model (JSOM) with Nintex Forms

Recently working on a project I came across an interesting scenario where I had to use Nintex form. As a part of the process the form will be querying multiple lists and displaying data on the form.

You can achieve this using the Nintex Form out of the box controls but there were specific requirements which could be achieved using the out of the box controls.

I decided to use the JSOM to complete the task and plugged in my JSOM code into Form’s custom JavaScript section. To my surprise when I ran the Nintex form nothing happened.

Quickly I figured that my code was getting executed before SharePoint finish loading all the files and required SP.js file was missing at the time of code execution.

So I tried Script on Demand to make sure that my function only gets executed after the SP.js is available.

Here is the code I have added to my Nintex form.

NWF.FormFiller.Events.RegisterAfterReady(function () {

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

}




function myFunction() {

.

.

.

.

}

Once I added that one line my code worked like a charm. So if you are working with Nintex forms and would like to use JavaScript Object Model then you might run into the same issue and in that case just make sure to use Script On-Demand.