Attach items (records) to a collection

<< Click to Display Table of Contents >>

Navigation:  Low-code Process Automation > Studio Cloud - Authoring environment > Bizagi Studio > Process wizard > Business Rules > Business Rules examples > Collections and entities > Collection examples >

Attach items (records) to a collection

Attaching an item of a collection is connecting an existing record from a table to another table, within the same case, sharing the information.

The item (record) will then belong to both tables, not duplicated, just shared. That is, when information of this record is updated, changes will be reflected in both tables.

 

If you need to move an item from one collection to another, you can do so by attaching the item to the new collection and detaching from the old collection. You don't need to duplicate and re-create.

 

To attach an item (or record) you have two options:

Attach some collection items: attaching some items (one or more records) of a collection to another one is done using the attachCollectionItems function.

You need to specify the XPath to the collection and the XPath filtering the items you want to attach.

 

Attach ONE collection item: attaching ONE item (record) of a collection is done using the attachCollectionItem function.

You need to specify the XPath to the collection and the XPath filtering the single item you want to attach. If more than one XPath is found the function will present an error to the end user.

 

The functions are found in the Collection category.

 

attach1

 

The syntax of the function is as follows:

 

Me.attachCollectionItem("ProcessEntity.RelationshipToTheCollection",filtered XPath)

Me.attachCollectionItems("ProcessEntity.RelationshipToTheCollection",filtered XPath)

 

Let's take a School process. Through the year the homeroom teacher is updating the student's grades and seeing who is approving and who is failing. There are three collections, the Student collection, with the updated information, the Approving collection and the Failing collection.

All of the are collections of the same Master entity: Students.

 

Detach1

 

When the Students collection is updated, we want to attach all students with an average over 6 to the Approved students and all students below 6 to the Failing students.

 

We use the attachCollectionItems function to attach from the Students collection to the Failing list and to the Approving list.

 

attach2

 

var average = 6;

Me.attachCollectionItems("School.Approvedstudents", Me.getXPath("School.Students[Average >= "+ average +"]"));

 

Me.attachCollectionItems("School.Failedstudents", Me.getXPath("School.Students[Average < "+ average +"]"));

 

Below you will find the different ways that elements can be attached depending on the business requirement.

 

Example

Result

Me.attachCollectionItems("School.Approvedstudents", Me.getXPath("School.Students[Average >= "+ average +"]"));

 

or

 

Me.attachCollectionItems("School.Approvedstudents", <School.Students[Average >= 6]>);

Attaches to the Approved students the ones that have average over 6.

if(<count(School.Students[Average > 6])>==1)

{

Me.attachCollectionItem("School.Approvedstudents", <School.Students[Average > 6]> );

}

Attaches the ONE student whose average is above 6 to the Approved collection, from the Students collection.

 

attach3


Last Updated 1/6/2022 4:15:18 PM