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

How to query a SharePoint list from another list in Nintex Forms for O365.

Querying a SharePoint list from another list in Nintex Forms 2013 and 2010 is possible using the lookup control, but how do we achieve this in Nintex Forms for 0ffice 365?

A. There is good news, custom Javascript and JSOM will allow us to achieve this, but how are we going to do that?

Scenario:

We have an Inventory List. In the Inventory Form, we would like to have a lookup which loads a list of products. When the lookup value changes, we would like to query our products list and return all the details of the selected product.

This can be achieved through JavaScript.

Since we already have our SharePoint client context loaded in our client, we can write scripts to query any list on that web using JSOM (JavaScript Object Model). Refer to code snippet below:


NWF$(document).ready(function(){


var obj = NWF$("#" + LookupProduct);


obj.change(function(){


      var web = clientContext.get_web(); 


      var oList = clientContext.get_web().get_lists().getByTitle("Products");


      var listItem = oList.getItemById(this.value);


      clientContext.load(listItem, "Title", "Code", "Price", "ImageUrl");


      clientContext.executeQueryAsync(function(){


           var img = NWF$("#image");


           var code = NWF$("#" + ProductCode);  


           var productPrice = NWF$("#" + ProductPrice);   


           var productName = NWF$("#" + ProductName);


           var imgUrl = listItem.get_item('ImageUrl');


           var imgUrlTextBox = NWF$("#" + ImageUrlVal);


           imgUrlTextBox.val(imgUrl);


           img.attr('src', imgUrl);


           code.val(listItem.get_item('Code'));


           productPrice.val(listItem.get_item('Price').toFixed(2));


           productName.val(listItem.get_item('Title'));


},


function(){ alert("Error");});


});


});



Referring to the snippet above, basically we are querying our product list with the id from the lookup control and populating a few textboxes with the details of the selected product.

Insert the code snippet in Form Settings > Custom JavaScript. Please make sure your ids of all your elements match.

Using this same concept and applying JSOM we can achieve many SharePoint related operations in our forms that makes Nintex Forms for Office 365 even more powerful. However, some lists might not be able to be queried due to permission levels.

Enjoy exploring and give it a go to unleash the full potential of Nintex Forms. Comments and ideas are most welcomed.

Reply
38 Replies
Highlighted
Nintex Newbie

Re: How to query a SharePoint list from another list in Nintex Forms for O365.

Jeremy,

This is great info.  I'm exploring more with 0365 and Nintex and this will definitely come in hand when I get to that point.

Reply
Highlighted
Not applicable

Re: How to query a SharePoint list from another list in Nintex Forms for O365.

Awesome!

Thanks for the great info. This (again) helped us a lot!

Reply
Highlighted
Not applicable

Re: How to query a SharePoint list from another list in Nintex Forms for O365.

No worries Davy. We from Nintex are always ready to help you guys

Reply
Highlighted
Automation Master
Automation Master

Re: How to query a SharePoint list from another list in Nintex Forms for O365.

Awesome post, thanks for sharing.

Reply
Highlighted
Not applicable

Re: How to query a SharePoint list from another list in Nintex Forms for O365.

While testing this I get the "SP is undefined" error. I don't know if this is normal or I forgot something?

Reply
Highlighted
Not applicable

Re: How to query a SharePoint list from another list in Nintex Forms for O365.

Hi Davy,

     Great that you have tried this, could you give me more info on your code so that I can check it out for you. If you are using the exact piece of snippet above, I believe you should not be getting any errors.

Thanks

0 Kudos
Reply
Highlighted
Not applicable

Re: How to query a SharePoint list from another list in Nintex Forms for O365.

I am having a hard time getting this to work.

I am trying to pull all of the information in an Assets Off Boarding list that is assigned to a specific user.

I have tried to replace the information as suggested but the form will not even load in preview mode.

When I turn on the Dev Tool Bar it is not finding the NWF$ but when I view the source it is showing in the code.  Additionally it is showing in a CDATA but rem'd out.

I could really use some additional help.

Dorinda

0 Kudos
Reply
Highlighted
Not applicable

Re: How to query a SharePoint list from another list in Nintex Forms for O365.

Hi Dorinda,

  Does it work in runtime? Its hard for me to know where you are going wrong without additional information.

Would be good if you could share some code and the form xml so I can assist you.

Thanks

Jeremy

0 Kudos
Reply
Highlighted
Nintex Newbie

Re: How to query a SharePoint list from another list in Nintex Forms for O365.

Hi Jeremy,

had some trouble earlier but found:

ExecuteQueryAsync - ((ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler).)

This helped me understand the code much better and I was ultimately able to find where I'd gone wrong.

However my current issue is "what next?" I have all my code in place however my text boxes in the form named: "ManagementArea" and "BMContractor" are not updating when I am changing the selection in "LookupSite" look up field. The code is there but I cant see it doing anything, do I need to add code to the text boxes/fields on the form also?

Many thanks,

Andrew

0 Kudos
Reply