<< Click to Display Table of Contents >> Add items (records) to a collection |
In order to create items (records) in a collection using a business rule, Bizagi offers a function called newCollectionItem.
Visualize your collection as a table. Creating a new item is comparable to adding a new row to a table. First you need to create the new row and then set the desired values for each column.
The new record (row) is created using the newCollectionItem function. This function is available in the Functions list of the Collections category.
The following shows the syntax of the function:
Me.newCollectionItem ("ProcessEntity.RelationshipToTheCollection")
In order to manipulate the new record (row) it must be assigned to a variable:
var Newrecord = Me.newCollectionItem ("ProcessEntity.RelationshipToTheCollection")
To set values to the columns (fields) of the new record it is necessary to apply the setXPath function to the variable we just created. This function has the following syntax:
Newrecord.setXPath ("Column",Value)
Note the parameters of the setXPath function are: the Column, which is the name of the attribute in the collection, and the Value that will be set.
To illustrate how to add a new item to a collection, suppose you have a Project Administration process where the necessary activities to accomplish a Project are planned and executed. Each project has many activities to perform:
We need to add new activities to an Event called Create new activity. In this event the information of the new activity is entered. When the Next button is clicked this information must be included automatically in the Activities collection table. Instances of the Perform Activities Sub-Process will eventuate for each record in the Activities collection.
In order to do this follow the next steps:
1. In the fourth step of the Bizagi Process Wizard (Business Rules), select Activity Actions.
Click the Event in which the project activities will be added and create an On Exit Expression.
2. Declare an object type variable.
3. Build an expression to add an element (a new record) to a collection (one-to-many relationship) and value the attributes of the many entity.
NewActivity=Me.newCollectionItem("ProjectAdministration.Activities");
The line above will create a new Activities row. Once the new row is created, the attribute values of the Activities entity can be set:
NewActivity.setXPath("Description",<ProjectAdministration.NewActivityDescription>);
NewActivity.setXPath("Responsible",<ProjectAdministration.NewActivityReponsible>);
NewActivity.setXPath("DueDate",<ProjectAdministration.NewActivityDueDate>);
The following is a graphical representation of the expression's execution:
In order to have a better performance, when manipulating data inside a cycle, before entering the cycle extract in a variable the Process entity and then use the variable inside the cycle.
Example:
var max = 1500; |
Last Updated 1/6/2022 4:15:41 PM