Creating composite transactions with looping logic
A composite transaction with looping logic allows you to iterate through a collection of objects and executes other requests based on each object. It is an extension of the basic composite transaction. (Refer to Understanding basic composite transactions before continuing with this section.)
The XML construct for the looping logic in the composite XML transaction
is very similar to the XSLT <xsl:for-each> syntax.
To include looping logic in a composite XML, use this syntax:
<for-each select="object-set-expression" var="varName">
<!-- One or more <TCRMService/> (or <DWLAdminService/>) or <choose/> -->
…
…
</for-each>
The <for-each> XML tag contains a mandatory select attribute
and a var attribute. The select attribute
points to an object-set-expression, which is the kind of expression
that will be evaluated to a collection of objects at runtime. The var attribute
is a reference name that you can give in order to associate it with
each object in the collection when the collection is iterated through.
When the reference name is used in the rest of the composite, the
reference name must be prefixed with a $ character.
Between the <for-each> and </for-each> XML
tags, you can include one or more <TCRMService> (or <DWLAdminService>) XML
requests. When the object-set expression is evaluated to return a
collection of objects, each of the requests will be executed as many
times as there are objects in the collection. You can also include
another <choose> XML between the <for-each> and </for-each> XML
tags. This in effect allows you do further qualify the loop with "if-then-else"
logic.
The following is a sample composite XML transaction with looping
logic. There are two requests in this composite: getPerson and updatePartyAddress.
The looping logic is as follows:
- Do a
getPersontransaction for party ID3004000123. - For each of the
TCRMPartyAddressBObjobjects returned from theTCRMPersonBObj:- If the
EndDatehas not been set, update theStartDate. - Otherwise, just produce an error message.
<DWLCompositeServiceRequest> <GlobalFields> … … </GlobalFields> <TCRMService> <RequestControl> <requestID>100181</requestID> <DWLControl> … … <!-- The correlator ID for the getPerson transaction in this composite is 111. --> <transactionCorrelatorId>111</transactionCorrelatorId> </DWLControl> </RequestControl> <TCRMInquiry> <InquiryType>getPerson</InquiryType> <InquiryParam> <tcrmParam name="PartyId">3004000123</tcrmParam> <tcrmParam name="InquiryLevel">3/tcrmParam> … … </InquiryParam> </TCRMInquiry> </TCRMService> <!-- The object-set expression in this <for-each> gets the collection of TCRMPartAddressBObj from the getPerson response. The anAddress variable is a reference to each TCRMPartAddressBObj in the collection, which will be used in the rest of the composite. --> <for-each select="id.111.response.TCRMPersonBObj.TCRMPartyAddressBObj" var="anAddress"> <choose> <!-- The boolean expression in this <when> tests if the EndDate in a TCRMPartAddressBObj has not been set. Note the use of the $anAddress variable to refer to each TCRMPartAddressBObj in the collection. --> <when test="$anAddress.EndDate = null"> <TCRMService> <RequestControl> <requestID>100190</requestID> <DWLControl> … … <transactionCorrelatorId>555</transactionCorrelatorId> </DWLControl> </RequestControl> <TCRMTx> <TCRMTxType>updatePartyAddress</TCRMTxType> <TCRMTxObject>TCRMPartyAddressBObj</TCRMTxObject> <TCRMObject> <TCRMPartyAddressBObj> <!-- Substitute all the necessary fields from the getPerson response and the new StartDate to update the party address. Note the use of the $anAddress variable to refer to each TCRMPartAddressBObj in the collection. --> <PartyAddressIdPK> {$anAddress.PartyAddressIdPK} </PartyAddressIdPK> <PartyId>{$anAddress.PartyId}</PartyId> <StartDate>2000-01-31</StartDate> … … </TCRMPartyAddressBObj> </TCRMObject> </TCRMTx> </TCRMService> </when> <!-- If the EndDate has been set, just produce an error message. --> <otherwise> <message errorId="6000" lang="100">Address already expired</message> </otherwise> </choose> </for-each> </DWLCompositeServiceRequest> - If the
For more information on object-set expressions, see Creating object-set expressions.
For more information on boolean expressions, see Creating boolean expressions.
For more information on substitution expressions, see Example: Substituting values from another Request or Response.
For more information on looking up error messages, see Providing error messages using the error handling service.