Detach (disconnect) elements of 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 >

Detach (disconnect) elements of a collection

Visualize your collection as a table. Detaching an item is disconnecting a row from a table but leaving the data in the database to be used after of by another collection.

 

Records in a collection can be deleted or detached.

When you delete a record it will be removed form the collection and from the database.

When you detach a record it will be disconnected from the collection but it will stay in the database.

 

When a record is shared by two or more collections, we recommend detaching instead of removing.

 

If you detach an item (or record) you have three options:

Detach all collection items: detaching all the items (records) of a collection is done using the detachAllCollectionItems function.

You only need to specify the XPath to the collection and all the records will be detached.

 

Detach some collection items: detaching some items (one or more records) of a collection is done using the detachCollectionItems function.

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

 

Detach ONE collection item: detaching  ONE item (record) of a collection is done using the detachCollectionItem function.

You need to specify the XPath to the collection and the XPath filtering the single item you want to detach. 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.

 

addrelation18

 

The syntax of the functions is as follows:

 

Me.detachAllCollectionItems("ProcessEntity.RelationshipToTheCollection")

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

Me.detachCollectionItem("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 detach from the Failing collections the ones whose average is now over 6 and another with the ones whose average is under 6.

We use the detachCollectionItems function to detach from the Failing list the students that are now approving.

We don't use the deleteCollectionItems function because we just want to disconnect the items from a collection, but still save them in the database, because they will be attached to the Approving collection, and are part of the main Students collection.

 

Detach2

 

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

 

Example

Result

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

{

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

}

Detaches only one student whose average is below six and belongs to the Approved collection.

var average = 6;

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

 

or

 

Me.detachCollectionItems("School.Failedstudents", <School.Students[Average > 6]>);

Detaches all students that were failing that now are approving. The items (students) will be disconnected from the Failing collection but will still be present in the data base.

Me.detachAllCollectionItems("School.Failedstudents");

 

Me.detachAllCollectionItems("School.Approvedstudents");

Detaches all elements from both relationships, but now from the data base.

Me.detachAllCollectionItems("School.Approvedstudents[Average < 6]");

Detaches all the students whose average is below six and that belong to the Approved collection.


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