A requirement came in from a customer asking if it would be possible to use information from ‘List A’ and use it as validation on another form. At first I tried to directly access the list using JavaScript, but this is prevented due to Cross Domain Scripting issues, instead, I needed to the SP.RequestExecutor functionality. This post will go through a simple of example of querying a list for an item and displaying it in an alert.

Firstly, the list to query has to be set up – for this example I created a simple custom list and used the out of the box title column. Image 1 shows the list that was created and used in this example.

List containing items to lookup
 Image 1) List containing lookup information

One of the first things that need to be done is to gather the SPHostUrl & SPAppWebUrl parameters from the query string, these will be used later when the executor is called.

In this example, the query is done as soon as the page has finished loading, whilst it may have been possible to directly use jQuery ready this seemed to cause intermittent issues where the query would run before Nintex had finished initializing so instead the NWF RegisterAfterReady functionality was used. Once Nintex has finished loading there is another query to get the SP.RequestExecutor script.

The list query is built up using the standard REST APIs. In this example, the query is selecting the Title field for items where the ID is 2. This is obviously a simple example but can be used as a base. The $expand functionality is supported as well.

The results are returned in JSON format which allows easy navigation through the objects. The example below only expects a single result, but .each was used as an example.

Below shows the output from the page. Now that the information has been retrieved it can be used in a custom validation event.

Alert containing lookup data
Alert created by the page

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.