Add items (records) to a collection

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business rules examples > Collection examples >

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.

 

addrelation6

 

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.

 

 

addrelation8

 

 

addrelation2

 

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.

 

addrelation4

 

2. Declare an object type variable.

 

addrelation3

 

 

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.

 

addrelation5

 

 

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:

 

removerel2