cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Using JSOM in Nintex Forms for O365

I'm following the post here: Nintex Forms O365 - Getting SharePoint ClientContext Do's and Dont's .

The post states to NOT load the SP.js script in your own code. Following the guidance there, the console throws an error
Uncaught ReferenceError: SP is not defined

If I do however load the SP.js script in my code, the error goes away but throws another error from the sp.js file:

Uncaught TypeError: Cannot read property 'isNullOrUndefined' of undefined

code below:

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

  loadScripts().done(function(){

       getDataFromSharePoint();

  });

})

var appwebUrl = NF.Url.getQueryStringParameter("SPAppWebUrl");

var hostUrl = NF.Url.getQueryStringParameter("SPHostUrl");

function loadScripts(){

  var def = NWF$.Deferred();

  var layoutsPath = "/_layouts/15/";

  var scriptsPath = hostUrl + layoutsPath;

  (function(){

       return NWF$.cachedScript(scriptsPath + "sp.js");

  })()

  .done(function(){

       def.resolve();

  })

  return def.promise();

}    

function getDataFromSharePoint(){

  var clientContext;

  var factory;

  clientContext = new SP.ClientContext(appwebUrl);

  factory = new SP.ProxyWebRequestExecutorFactory(appwebUrl);

  clientContext.set_webRequestExecutorFactor(factory);

  var web = clientContext.get_web();

  var list = clientContext.get_web().get_lists().getByTitle("Potential Projects");

  clientContext.load(list);

  clientContext.executeQueryAsync(function(){

       console.log(list);

  },

  function(){

       console.log('fail')

  });

}

Does anyone have any success with JSOM on Nintex Forms on O365?

What am I doing wrong?

Thanks,

-Aaron

Edit: formatting

Labels: (1)
Tags (2)
Reply
3 Replies
stuart_holding
Nintex Newbie

Re: Using JSOM in Nintex Forms for O365

Hi Aaron,

Did you get any traction with a solution for this?

0 Kudos
Reply
Not applicable

Re: Using JSOM in Nintex Forms for O365

Hi Stu,

Unfortunately no. Another post here: How to query a SharePoint list from another list in Nintex Forms for O365. explains that "Since we already have our SharePoint client context loaded in our client...." but it never shows how the client context is loaded. If we attempt to get the client context at that time (through docready), it comes up as undefined.

We only get a client context when we attach our code to a button click on the form. And that seems like it's a race condition of the form not loading SP.js in time for our code to run on the docready.

Any help is appreciated

0 Kudos
Reply
Not applicable

Re: Using JSOM in Nintex Forms for O365

After poking around for a bit, I came up with a solution that polls for clientContext

var pollSP;

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

    pollSP = setInterval(checkSPLoad, 500);

});

   

function checkSPLoad(){

    if (clientContext){

        window.clearInterval(pollSP);

        onSPLoad();

    }

}

function onSPLoad(){

    var list = clientContext.get_web().get_lists().getByTitle("ListTitle");

    clientContext.load(list);

    clientContext.executeQueryAsync(function(){

        console.log(list);

     });

}

just insert your code into the onSPLoad function.

Reply