You can add decisions to a composition script using the if statement.

For example, you may want to invoke a particular service only if the called party address starts with a particular prefix.

The <if> statement contains a conditional expression, a <then> element, and optionally <else-if> and <else> elements. The <then> and <else> elements may contain any composition statement for the SIS to evaluate, depending on the outcome of the expression.

The SIS only evaluates conditional expressions in a composition while processing the initial request. While doing this, the SIS implicitly reads variables from the current input request, which is: the initial request the SIS received from the network, if it has not invoked any service before processing the expression; or (if it has invoked a service), the response to a request from the last service the SIS has invoked.

Note After completing initial event processing, the SIS limits the set of services it has invoked for future events on the call to those invoked during initial event processing. If the service selection included conditional logic, the SIS retains decisions made during initial event processing for future events on the same call — it does not re-evaluate conditional expressions for subsequent events.{ocpanel}
Tip
Loop-proof

The composition script language is deliberately constrained so as to make loops impossible — so a badly-written composition will never cause the SIS to enter an infinite loop. (However you can invoke the same service multiple times in the same composition, if necessary).

Initial request

With <if> at the beginning of a script, the SIS evaluates the conditional expression before invoking any services. Therefore, it takes the values of any variables used in the expression from the initial request. The following example shows a script that invokes different services depending on the value of the from.uri.user parameter from the initial request:

VIA diagram

if initial request

Script XML

<script>
  <if><equal a="${from.uri.user}" b="alice"/>
    <then>
      <invoke service="AliceSpecial"/>
    </then>
    <else-if><equal a="${from.uri.user}" b="bob"/>
      <then>
         <invoke service="BobSpecial"/>
      </then>
    </else-if>
    <else>
      <invoke service="NoSpecial"/>
    </else>
  </if>
</script>

Response from service

With <if> after an <invoke> element, the SIS evaluates the conditional expression after invoking and processing the output from the previous service.

In the following example, the SIS invokes the VPN service, and then evaluates the if statement. It will read the variable from.uri.user from the new request that came from invoking the VPN service. If the VPN service changed the value of from.uri.user when it processed the request, the SIS will see that new value here. If the new request matches the condition, the SIS invokes the BobSpecial service. Finally the SIS invokes the Prepay service unconditionally.

VIA diagram Script
if response
<script>
  <invoke service="VPN"/>
  <if><equal a="${from.uri.user}" b="bob"/>
    <then>
      <invoke service="BobSpecial"/>
    </then>
  </if>
  <invoke service="Prepay"/>
</script>
Previous page Next page