Run Assertions for Each Item Assertion

The Run Assertions for Each Item assertion is a composite assertion that behaves similarly to the , with the exception that it may evaluate its child assertions more than once (as a loop) or possibly not at all, depending on the context variable it is configured to use.
Run Assertions for Each Item
assertion is a composite assertion that behaves similarly to the All Assertions Must Evaluate to True Assertion, with the exception that it may evaluate its child assertions more than once (as a loop) or possibly not at all, depending on the context variable it is configured to use.
This assertion evaluates its child assertions once for each member of the specified multivalued context variable. If the multivalued variable is empty or does not exist, the assertion always succeed and does not evaluate any of its child assertions.
Avoid using a debug trace policy when the Run Assertions for Each Item assertion is present in a policy, especially if the assertion is nested beneath another Run Assertions for Each Item assertion. Doing so can cause the trace policy to be invoked a large number of times, potentially impacting system performance, and generating excessively large trace logs.
The following example illustrates how the Run Assertions for Each Item assertion might be used. In the sample policy fragment below, you send a list of greetings to a pair of URLs.
image2015-1-5 9:39:11.png
The following table explains each line in the policy example:
The Set Context Variable assertion creates a new variable named messages, with the content “Hi there|How are you doing|Greetings”.
The Split Variable assertion breaks up the value in messages into a new multivalued context variable name
. The break occurs at the “|” character.
The Run Assertions for Each Item assertion, using
as the input and “sample” as the variable prefix. When you point at this with the mouse, a tooltip displays the context variables that are created by this assertion, using the variable prefix entered.
The first child assertion. This uses the Set Context Variable assertion to create a new variable named message2. Set this variable to whatever is in
for that iteration. This is specified by the context variable
. Thus, for the first iteration, message2=Hi there; for the 2nd iteration, message2= How are you doing, etc.
The Route via HTTP(S) assertions are configured to use the context variable
as a request message source. The message contained in the variable message2 is updated on each iteration and sent to the two URLs. This results in the following POST commands:
POST "Hi there" to firsturl
POST "Hi there" to secondurl
POST "How are you doing" to firsturl
POST "How are you doing" to secondurl
POST "Greetings" to firsturl
POST "Greetings" to secondurl
If any of the POST requests fail to reach the target server, the Run Assertions for Each Item assertion fails and the remaining POSTS are not attempted.
When the
Run Assertions
for Each Item
 assertion is finished, the
variable contains “3”, while the
variable contains “false”.
For more information on multivalued context variables and how they work, see Multivalued Context Variables.
Terminating the Execution of Child Assertions
It is possible to terminate the execution of the child assertions prior to the completion of the loop. To do this, set the following context variable, either inside or outside of the loop:
Variable name
Variable value
: true
When set outside of the loop, the loop is terminated immediately. When set inside the loop, the loop completes its iteration before terminating.
Use the Set Context Variable Assertion to create the variable and set the value to true.
Context Variables Created by This Assertion
The Run Assertions for Each Item assertion sets the following context variables. The <
> is set in the assertion properties. There is no default.
The current member of the multivalued variable. During iteration, the
variable takes on the value of each member of the multivalued variable. After iteration, it remains set to the last value it had. If the multivalued variable existed but was zero-length, then the 
t variable will not exist after iteration has finished.
The number of iterations that have been completed successfully.
This variable contains "true" if the assertion ended because the iteration limit was reached, otherwise it contains "false". While processing is in progress, this variable always contains "false".
Using the Assertion
  1. Do one of the following:
    • To add the assertion to the Policy Development window, see Add an Assertion.
    • To change the configuration of an existing assertion, proceed to step 2 below.
  2. When adding the assertion, the
    Run Assertions for Each Item Properties
    automatically appear; when modifying the assertion, right-click
    Run Assertions for Each Item
    in the policy window and select
    Run Assertions for Each Item Properties
    or double-click the assertion in the policy window. The assertion properties are displayed. 
  3. Configure the properties as follows:
    Name of Existing Multivalued Variable
    Specify the name of the variable to iterate over.
    If this variable is empty, the assertion always succeeds and none of the child assertions are evaluated.
    Variable Prefix
    Enter a prefix that is added to the context variables created by this assertion. This prefix ensures uniqueness and prevents the variables from overwriting each other when multiple instances of this assertion appear in a policy.
    For an explanation of the validation messages displayed, see "Context Variable Validation" under Context Variables.
    Limit Maximum Iterations
    Optionally, you may limit the number of iterations by selecting this check box and entering the maximum number of iterations in the corresponding field. If a maximum is not specified, then the assertion attempts to process all members in the multivalued context variable.
    If specified, iteration will halt after the child policy has invoked this many times, regardless of whether it has been invoked for all members in the multivalued variable.
    After the iterations are complete, the context variable
    will be set to "true" if this limit was hit. Otherwise, it is set to "false".
    Resolving stack trace errors:
    If you choose to not limit the number of iterations but are experiencing stack trace errors, try doing the following:
    1. Access the properties for the appropriate listen port. For more information, see Listen Port Properties.
    2. Select the [Advanced] tab.
    3. Add this advanced property:
    maxHttpHeaderSize =
    , where '<value>' is expressed in bytes.
    When not specified, the
    Layer7 API Gateway
    uses a value of 8192 (8KB).