In situations where we have information in a list of the same elements, it is not possible to access a variable by name. Rather, we use indexing to access the variable data from a list.
We will examine dynamic indexing of the variables in the Manipulate1_1
BPEL process from the Assigning date or time to the variables recipe.
First, let's extend the BPEL process by defining a new element in the Manipulate1_1
schema file as follows:
<element name = "ChildrenElementType"> <complexType> <sequence> <element name = "child" type = "string" minOccurs = "1" maxOccurs = "unbounded"/> </sequence> </complexType> </element>
The Element-type variable is defined as an array of the <child>
strings.
Also, we modify the request and response messages of the BPEL process. We amend the request message with the following element:
<element name = "child_no" type = "integer"/>
We will use this to input the element in the child
list we want to query. We add the following element to the response message:
<element name = "child_selection" type = "string"/>
The Element-type variable will contain information about the selected child from the list.
In order to dynamically index the variable contet, we perform the following steps:
DynamicScope
) and sequence activity (DynamicSequence
) into our BPEL process.ChildSelection
variable holds information about the list. We define index
to perform the dynamic query in the list.<variables> <variable name = "ChildSelection" element = "client:ChildrenElementType"/> <variable name = "index" type = "xsd:integer"/> </variables>
InitChildren
) to initialize the list of information as follows:<assign name = "InitChildren"> <copy> <from><client:ChildrenElementType xmlns:client = "http://xmlns.oracle.com/Variables/Global/Manipulate1_1"> <client:child>Ajda</client:child> <client:child>Urban</client:child> </client:ChildrenElementType></from> <to variable = "ChildSelection"/> </copy> </assign>
switch
activity with two decision branches. The positive branch checks if the child_no
element is set in the request message and in the specified range. <case condition = "bpws:getVariableData('inputVariable','payload', '/client:process/client:child_no') < 3 and bpws:getVariableData('inputVariable','payload', '/client:process/client:child_no') > 0">
<assign name = "GetDynamic"> <copy> <from variable = "inputVariable" part = "payload" query = "/client:process/client:child_no"/> <to variable = "index"/> </copy> <copy> <from expression = "bpws:getVariableData('ChildSelection','/client:ChildrenElementType')/client:child[bpws:getVariableData('index')]"/> <to variable = "outputVariable" part = "payload" query = "/client:processResponse/client:child_selection"/> </copy> </assign>
<assign name = "AssignNoAction"> <copy> <from expression = "'No value for selection or selection out of bounds'"/> <to variable = "outputVariable" part = "payload" query = "/client:processResponse/client:child_selection"/> </copy> </assign>
<inputVariable> <part name = "payload" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"> <ns1:process xmlns:ns1 = "http://xmlns.oracle.com/Variables/Global/Manipulate1_1"> <ns1:input>Jurij</ns1:input> <ns1:item>PC</ns1:item> <ns1:priceVAT>1234</ns1:priceVAT> <ns1:child_no>2</ns1:child_no> </ns1:process> </part> </inputVariable>
<outputVariable> <part name = "payload" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"> <processResponse xmlns = "http://xmlns.oracle.com/Variables/Global/Manipulate1_1"> <result>Jurij</result> <priceNet>1028.33</priceNet> <vat>205.67</vat> <child_selection>Urban</child_selection> </processResponse> </part> </outputVariable>