Creating an array node in a document instance
A document instance that represents an array of objects can store multiple inputs from processes and connectors in the array. In such a document instance, you can insert an array node at a given index or append it at the end. The node value can be a simple data type or a complex object. You can also remove a node from the given index.
Adding or removing an array element returns an updated document instance. Therefore, you must map this action to some document instance. Ideally, map the adding and deleting action to a document instance that you have supplied as input.
Important
Adding an array node is supported only in the Process designer. You cannot add an array node in the Rule designer.
Related topics
Example
A user wants to update his home address on an online shopping portal. He also wants to add his office address in his profile, on the same portal. So, he goes to his profile, updates the existing address, and adds his new office address.
Before you begin
Make sure that you have created a document instance with the following JSON:
{
"name":"",
"empId":"",
"address": [{"building name": "", "building no": ""}]
}
For more information, see Creating-a-document-instance.
To add an array node
- Log in to BMC Helix Innovation Studio.
- From the Workspace tab, navigate to the application for which you want to add an array node.
- In the Process designer, create a new process or navigate to the process in which you want to add the array element.
- In Process designer, from the Palette, drag the Add Array Element To Document element onto the canvas.
In the Element Properties pane, enter the properties for the Add Array Element To Document element, as described in the following table:
Property
Description
GENERAL
Label
Enter a suitable name for the element.
Description
Enter details about the element.
INPUT MAP
Document Definition Name
Select the document definition that you want to use for this process.
Document Instance
Capture this information from a process variable or other inputs.
Node Name
Enter the node name of the array element.
Value
Enter the value to be added to the array element.
Index
(Optional) Specify the index at which you want to add the value in the array.
If you enter an invalid input, such as a negative value or a value more than the array size, the input is ignored and the value is appended at the end of the array.
Replace
(Optional) Select this option if you want to replace the element at the specified index. When Replace is selected (True), the new element replaces the old element. When the Replace option is not selected (False), the new element is inserted at the given index.
MULTI INSTANCE LOOP
Loop Type
Select Parallel or Sequential from the list.For information about Multi instance loop, see Creating-process-steps-or-activities.
GEOMETRY
Source
Select the document definition that you want to use for this process.
- Click Save.
In this example, because the index is 2 and replace is false, the new value is added at index 2.
documentInstance = {
"name":"Seth", "empId":"123",
"address": [{"building name": "Home", "building no": "2"}, {"building name": "Office", "building no": "A"}]
}
nodeName = "address"
value ={
"building name": "Sales Office", "building no": "5"
}
index = 2
replace = false
Output:
{
"name":"Seth", "empId":"123",
"address": [{"building name": "Home", "building no": "2"}, {"building name": "Office", "building no": "A"}, {"building name": "Sales Office", "building no": "5"} ]
}
To replace an array node
- Log in to BMC Helix Innovation Studio.
- From the Workspace tab, navigate to the application for which you want to create a process to replace an array element.
- In the Process designer, create a new process or navigate to the process in which you want to replace the array element.
- In Process designer, from the Palette, drag the Add Array Element To Document element onto the canvas.
In the Element Properties pane, enter the properties for the Add Array Element To Document element, as described in the following table:
Property
Description
GENERAL
Label
Enter a suitable name for the element.
Description
Enter details about the element.
INPUT MAP
Document Definition Name
Select the document definition that you want to use for this process.
Document Instance
Document instance is a required input that you can capture from a process variable or other inputs.
Node Name
Enter the node name of the array element.
Value
Enter the value to be added in the array element.
Index
(Optional) Specify the index at which you want to add the value in the array.
If you enter an invalid input such as a negative value or a value more than the array size, the input is ignored and the value is appended at the end of the array.
Replace
Select this option if you want to replace the element at the specified index. The new element replaces the old element.
MULTI INSTANCE LOOP
Loop Type
Select Parallel or Sequential from the list.For information about Multi instance loop, see Creating-process-steps-or-activities.
GEOMETRY
Source
Select the document definition that you want to use for this process.
- Click Save.
In this example, because index is 0 and replace is true, the element at index 0 is replaced with the new value.
documentInstance = {
"name":"",
"empId":"",
"address": [{"building name": "Home", "building no": "2"}, {"building name": "Office", "building no": "A"}]
}
nodeName = "address"
value ={"building name": "Sales Office", "building no": "5"}
index = 0
replace = true
Output:
{
"name":"",
"empId":"",
"address": [{"building name": "Sales Office", "building no": "5"}, {"building name": "Office", "building no": "A"}]
}
To remove an array node
- Log in to BMC Helix Innovation Studio.
- From the Workspace tab, navigate to the application for which you want to create a process to remove an array element.
- In the Process designer, create a new process or navigate to the process from which you want to remove the array element.
- In Process designer, from the Palette, drag the Remove Array Element To Document element onto the canvas.
In the Element Properties pane, enter the properties for the Remove Array Element From Document element, as described in the following table:
Property
Description
GENERAL
Label
Enter a suitable name for the element.
Description
Enter details about the element.
INPUT MAP
Document Definition Name
Select the document definition that you want to use for this process.
Document Instance
Document instance is a required input that can be captured from a process variable or other inputs.
Node Name
Enter the node name of the array element.
Index
Specify the index at which you want to remove the value in the array.
If you enter an invalid input such as a negative value or value more than the array size, then the input is ignored.
- Click Save.
In this example, because index is 1, the element at index 1 is removed.
documentInstance = {
"name":"",
"empId":"",
"address": [{"building name": "Home", "building no": "2"}, {"building name": "Office", "building no": "A"}]
}
nodeName = "address"
index = 1
Output:
{
"name":"",
"empId":"",
"address": [{"building name": "Home", "building no": "2"}]
}