SelectNode Use Examples

Basic Use Example

In this example, we have a Node followed by a SelectNode. If we run in step so that the SelectNode does not have a chance to run yet, the Node output has 5 results.

If we look at the SelectNode configuration, we can see the StartIndex is set to 1 and the EndIndex is set to 3. Since I gave each of our nodes a visible index, after SelectNode runs, we will be able to expand the node and see which indexes were selected and which were dropped from the logs.

In the logs below we can see only 3 Node results are present. If we expand them, the nodes left have an index value of 1, 2, and 3.

SelectNode successfully selected a subset of the given Node and altered the logs to only display the range given by the StartIndex and EndIndex. Here is how the SelectNode logs appear:

Using 0 for StartIndex

The SelectNode service starts the indexing of the Node at 1. So, when you give it a StartIndex of 0, it still has the same behavior as if it were given a StartIndex of 1.

Used in a REST API for Paging of Results

In this example, SelectNode was usedin a GetOrderDetails REST API. The REST request would send an input of the StartIndex and EndIndex. This way the request could specify “I want only the first 10 results”. This is because the page would only show 10 at a time. Then as the user wanted to scroll through other pages, the API could be called again with a StartIndex of 11 and EndIndex of 20. Here is the process canvas for this API and the input in EASYProcess vs the JSON request used to call the API.

First we are going to call the API without sending a FromRecord or ToRecord. The default behavior it to select 1 and 999 when no values are passed in so that the results are not limited. Here is that logs in the SelectNode service:

In the logs, we can see that this order has 4 records returned from GetOrderDetails.

Next we are going to call the API with a ToRecord of 2 and a FromRecord of 1. After looking at the logs, we can see the same order has its GetOrderDetails results limited to 2:

Using SelectNode to Clear Output

Sometimes when dealing with loops, you will want to clear the previous output of a query so that it does not interfere with your next loop iteration. Let's say you are going to loop multiple times. During the loop, you don’t want a service of the same name to override the existing output. You want them to stack so that at the end of the loop you can look back at all of the nodes with that name and use it. However, after this loop iteration, you want a fresh start.

This can be done with SelectNode. Simply set the StartIndex and EndIndex to 0. This will select an empty subset of the Node and clear it from the logs.

Notice how in the above example, only the targeted node was removed (WorkData/RunQuery). The WorkData/RunQueryInfo node is considered separate and still remains. If you needed to remove all reference of this node, the success of WorkData/RunQuery, the info node, and the possible failure would all need to be targeted.

See below this example where there are three SelectNode services each targeting a different case.

The first Inquire is set to return one result. The second Inquire is set to return an exception. Below are the logs as they change with each next run service.

Inquire Output Before SelectNode Services

Inquire Output After Running RemoveException

Inquire Output After Running RemoveSuccess

Inquire Output After Running RemoveInfo

While using three different services to catch all nodes created from the Inquire will achieve the desired results, it can be optimized.

Logic Used: WorkData/*[name()='Inquire' or name()='InquireException' or name()='InquireInfo']

Using XSLT predicates, we can target all children of WorkData with a name of “Inquire”, “InquireException” or “InquireInfo”. This will remove all three nodes at once. Using this method you can perform the same action as multiple SelectNode services with one.

Inquire Output Before SelectNode Services

Inquire Output After Running RemoveAll