Skip to main content

Hi All,

I have tried using below methods to get my data from a sharepoint list but with no success as it always throw me some kind of errors(mentioned below)

 

Methods I used:

 1.

var web;

var hostweburl;

var appweburl;

var pollSP;

var testList = "Testlib";

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

pollSP = setInterval(checkSPLoad, 500);

});

// Once Nintex loads clientContext — perform setup functions

function checkSPLoad() {

if (clientContext) {

window.clearInterval(pollSP);

sharePointReady();

}

}

function sharePointReady() {

hostweburl = decodeURIComponent(Utils.getQueryStringParameter('SPHostUrl'));

appweburl = decodeURIComponent(Utils.getQueryStringParameter('SPAppWebUrl'));

var scriptbase = hostweburl + '/_layouts/15/';

NWF$.getScript(scriptbase + 'SP.Runtime.js',

function () {

NWF$.getScript(scriptbase + 'SP.js',

function () { NWF$.getScript(scriptbase + 'SP.RequestExecutor.js', onSPLoad); }

);

}

);

}

function onSPLoad() {

// Only executed once the page's document object model (DOM) is ready.

NWF$().ready(function () {

Data.onLoad();

});

}

var Data = {

onLoad: function() {

Data.load();

},

load: function() {

Data.getListData();

},

getListData: function() {

var context;

var factory;

var appContextSite;

context = new SP.ClientContext(appweburl);

factory = new SP.ProxyWebRequestExecutorFactory(appweburl);

context.set_webRequestExecutorFactory(factory);

appContextSite = new SP.AppContextSite(context, hostweburl);

var executor = new SP.RequestExecutor(appweburl);

executor.executeAsync({

url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + testList + "')/items?@target='" + encodeURIComponent(hostweburl) + "'",

method: "GET",

headers: {

"Accept": "application/json; odata=verbose"

},

success: function(data) {

var obj = JSON.parse(data.body);

alert(obj);

},

error: function (err) {

alert(JSON.stringify(err));

},

});

},

};

var Utils = {

getQueryStringParameter: function (param) {

var params = document.URL.split('?')'1].split('&');

var strParams = '';

for (var i = 0; i < params.length; i = i + 1) {

var singleParam = params.split('=');

if (singleParama0] == param) {

return singleParama1];

}

}

}

}

 

2.  function Test()
{
var selectedUser =U];
var URL= webUrl + "web/lists(guid'" + guid + "')/items?$select=* &$filter="filter";
NWF$.ajax({
url: URL ,
method: "GET",
headers:{
"accept": "application/json;odata=verbose",
"X-RequestDigest": NWF$("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose"
},
success: function (data) {
selectedUser = data.d.results;
},
error: function (xhr) {
alert(xhr.responseText);
}, async: false
});
return selectedUser;
}

 Errors which I am getting  :

-->Sometimes 403 FORBIDDEN

-->params.split is not a function

--> SP.ClientContext is not a constructor

-->Uncaught SyntaxError: missing ) after argument list

 

The thing is when I was working on Nintex forms on-prem there were no issues like this.

Any help is appriciated

 

Hi,

is there any specific reason why you are using jquery rather than calculated control and lookup functions?

Regards,
Tomasz

Hi

Yes, as I am populating so many fields using code in my forms, it's easy to get the whole infomation on one object and then parse through it to get the required data and populate at once just by NWF$("#"+ ID).val().

I was working with On-prem Sharepoint and their the Rest queries are straight forward and you get what you query for, but on O365 we have to use Client Context and that is creating some issues for me. 

Also please share any thoughts how to get current user and their Manager using jquery that woud be

fantastic

Regards


Reply