jeremy.jayaraj

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

Discussion created by jeremy.jayaraj Employee on Aug 11, 2014
Latest reply on Jan 17, 2017 by swaminathan

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.

Outcomes