cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Nintex Forms - getting list items by javascript

Jump to solution

Dear Community, 

Couldn't find any posts that helped me, so I create a new one...

I'm trying to get item information from a list based on a lookup field. 

So I implemented a little javascript that's fired by a button.

function updateSupplierTemplate(){
var ctx = new SP.ClientContext.get_current();
var myList = ctx.get_web().get_lists().getByTitle('SupplierTemplates');
ctx.load(myList);
var templateID = NWF.RuntimeFunctions.parseLookup(NWF$("#" + supplierTemplate).val(), false);
var myItem = myList.getItemById(templateID);
ctx.load(myItem);
ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
alert('success');
alert(myItem);
NWF$("#" + supplierStreet).val(sStreet);
}
function onQueryFailed(sender, args) {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}

I could see with an alert box, that my lookupID variable is set fine. 

Also the SP.Context must be available because it returns an [object] in an alert box.

The query goes in success function what I checked with an alert action. But as soon as I want to access myItem it returns "object not defined" in the developer function of the browser. 

Is this not a supported way to work with SP items inside a Nintex form?

Thanks for any help in advance.

Rubi

Reply
4 Replies
Workflow Hero

Re: Nintex Forms - getting list items by javascript

Jump to solution

What do you get on templateID ?

Reply
Workflow Hero

Re: Nintex Forms - getting list items by javascript

Jump to solution

Try this code :

function updateSupplierTemplate(){
var ctx = new SP.ClientContext.get_current();
var myList = ctx.get_web().get_lists().getByTitle('SupplierTemplates');
ctx.load(myList);
var templateID = NWF.RuntimeFunctions.parseLookup(NWF$("#" + supplierTemplate).val(), false);
alert(templateID);
var myItem = myList.getItemById(templateID);
ctx.load(myItem);
alert(myItem);
ctx.executeQueryAsync(
function() {
alert('success');
alert(myItem);

NWF$("#" + supplierStreet).val(sStreet);
},
function(sender, args) {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
);

}

0 Kudos
Reply
Workflow Hero

Re: Nintex Forms - getting list items by javascript

Jump to solution

Make use of REST query which gives you much clarity on what is going on and takes less lines. 

function GetTitle()
{
alert("method called");
var _siteUrl = _spPageContextInfo.webAbsoluteUrl;
var listname = "MyList";
var id = NWF.RuntimeFunctions.parseLookup(NWF$("#" + varParentItemID).val(), false);
NWF$.ajax({
url: _siteUrl + "/_api/web/lists/getbytitle('" + listname + "')/items(" + id + ")",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var _resultSet = data.d;
try {
NWF$("#" + varTitle).val(_resultSet.Title);
}
catch (e)
{
alert(e);
}

},
error: function (data) {
failure(data);
}
});
}

Reply
Workflow Hero

Re: Nintex Forms - getting list items by javascript

Jump to solution

Dear Saud Kathri, 

thank you for your help, but it ended up in exactly the same way.
The REST way worked on first attempt - for what reason ever.

Best regards,

Rouven

Reply