List Processing

Including long lists of items in action text fields.

Introduction

When defining actions, you may find yourself in situations where you need to process or inform about (or both) comprehensive lists of items. Here are some examples of such lists:

  • Bill of material
  • Sales order
  • List of ingredients
  • Warehouse inventory

In principle , it would be possible to enumerate all the items of such a list in the respective part of an action (request payload, body of an email or in-app alert). However, doing so could lead to different kinds of problems:

  • Wrong entries as a typical side effect of any tedious and boring task.
  • In case of very large lists, the size limits of the text fields used for action configuration might be exceeded.

To cope with these challenges, the Action Modeler of SAP IoT provides a feature for addressing all the items in a given list with minimum effort and space needed.

Details

To make addressing large amounts of items easier at design time, Action Modeler offers a special syntax to be used in certain text fields. The basic approach is to include a reference to a particular container-like entity of which you know it represents a list of equally structured items. The syntactical tags used for the container entity are then indicating that the system shouldn't deal with the container entity, but with the items it contains. Actually, the system performs a loop over all the items found in the container and processes them as desired.

Syntax

The following syntax elements are available for list processing:

List Processing Syntax Elements
Annotation Explanation
<#list>...</#list>

The <#list> tag is used for listing a sequence or collection of items. It simply outputs all the items of the content enclosed by the tags (for example, a collection of event data, an array of Strings like [January, February, March], etc.).

<#sep>...</#sep>

(Optional) Used in conjunction with the <#list> tag. Indicates that the text after the tag shall be used as a separator between each list item, except for the last item.

When used immediately before the closing </#list> tag, there's no need to enter the closing </#sep> tag. Otherwise, the <#sep> tag requires a closing tag.

Output Rendering

When using list processing annotations in the payload of an action, the positioning and arrangement of these elements has a direct impact of the output rendering. To illustrate that, compare the following examples:

Payload Example

The following example illustrates an action payload used to iterate through the items of a purchase requisition:

At runtime, this payload is resolved to the following result (JSON):