Nintex Workflow

Nintex Workflow – Querying a List with Paging

When you have a large number of items in a list and you need to query them, sometimes querying the whole lot using the Query List action is not the best practice. Depending on the number of items, you could potentially get a timeout on the workflow that will process each one.  The best practice maybe to query the list using paging.

Paging is best described as processing in pages or blocks of data.  In this case, we are processing a number of items at a time.

eg.  Let’s say you have 25 items.

You could process these in lots of 10.

It’s end up looking like this:

Process – 10 items

Process – 10 items

Process – 5 items

Currently, the Query List action allows you to set the row limit of your results.  But this will always return that number of items from the beginning of the result set.  There’s no way of getting the next set of results using that action.

To solve this conundrum, we can instead call the SharePoint Lists.asmx web service, specifically the GetListItems web method.

GetListItems and Paging

GetListItems supports not only RowLimit but also Paging.  In the QueryOptions node of the CAML query, there is a <Paging> node that has a “ListItemCollectionPositionNext” attribute.  For the first call to GetListItems, you can leave this empty.  But the data you get back will contain a ListItemCollectionPositionNext attribute, and you can use that in the following call to GetListItems.

With each call to GetListItems, retrieve the ListItemCollectionPositionNext and use it in the next call, etc, etc.

Solution

To make the usage of GetListItems more reusable and to not require workflow designers to know about Web Services or know about high level credentials, we can hide this functionality into a Nintex Workflow User Defined Action.

The User Defined Action will take 3 input parameters:

1. ListName – name of the list you want to query

2. RowLimit – number of items you want to get back per page

3. Paging – text used to get to a specific page of data

The User Define Action will also take 2 output parameters:

1. PagingOutput – this is the value of ListItemCollectionPositionNext that is returned from the web service call

2. XMLResult – the data returned from the web service call

User Defined Action

The User Defined Action will make the web service call.  It will also parse the results from the call to extract the ListItemCollectionPositionNext so that we can make further calls.

When there is no more data to retrieve, this attribute will be empty. 

The Web Service SOAP packet looks like this:

<?xml version=”1.0″ encoding=”utf-8″?>
<soap:Envelope xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/“>
    <soap:Body>
        <GetListItems xmlns=”http://schemas.microsoft.com/sharepoint/soap/“>
            <listName>{WorkflowVariable:ListName}</listName>
            <viewName></viewName>
            <query></query>
            <viewFields></viewFields>
            <rowLimit>{WorkflowVariable:RowLimit}</rowLimit>
            <queryOptions>
              <QueryOptions>
                <Paging ListItemCollectionPositionNext=”{WorkflowVariable:Paging}”></Paging>
              </QueryOptions>
            </queryOptions>
            <webID></webID>
        </GetListItems>
    </soap:Body>
</soap:Envelope>

The Nintex Workflow we created to call this user defined action, will go into a loop and continue retrieving data, parse the data and keep doing this until it finishes processing all the data.

Call the UDA looks like this :

Call UDA

If you have any questions regarding how the workflow works, shoot me a message.

Downloads 

Nintex Workflow 2010 : v2.3.5.0

Download the GetListItems Next Page User Defined Action (UDA format)

Download the GetListItems Next Page User Defined Action (NWF format)

Download the GetListItems Paging Test Workflow

Leave a Reply