<< Click to Display Table of Contents >> Add and remove records from My Stuff |
When you want to add and remove items to a Persona My Stuff you can do so by means of an expression.
To relate records to My stuff you must consider if the record to add is already created, and thus must be attached, or it is a new record.
Also consider if the Persona is the sole user owner of the record, of if other Persona can own (see the record in My Stuff) as well.
Example
Imagine in a car dealership you need to design a solution where clients can add and remove vehicles from a favorites list. You can do this using an expression to allow adding a record of a vehicle to a collection in My Stuff, and once there, use another rule action to remove the item from My Stuff.
What you need to do
1. Create the data model that will support the scenario
2. Enable the entity in My Stuff
3. Create a Search to find vehicles to add to Favorites
4. Create an action to add a vehicle to Favorites
5. Create an action to remove a vehicle from Favorites
Create the data model that will support the scenario
The first thing we need to notice is that many customers can add the same car to their favorites, thus, a car can be included as favorite in the list of many customer. Then we cannot have a direct collection from Client to Vehicle, because this would imply ownership. It would not allow the scenario described above where we need several customers being able to select several vehicles.
To be able to model the requirement we will use an intermediate entity between vehicles and clients, and we will call it Favorite vehicles. Both Vehicle and Client entity will have a one-to-many relationship with it.
Enable the entity in My Stuff
With this approach, the entity that we need to link to the Persona's Clients definition is the new Favorite Vehicles entity.
Go to My Stuff and enable the collection to Favorite vehicles in the Always available context.
Create a Search to find vehicles to add to Favorites
In the Persona create a search to enable searching for vehicles in the project
Create an action to add a vehicle to Favorites
We need a button to be displayed on the vehicle records when a Client search for them. Thus, we will select the Vehicles entity to be the one where the action is executed.
Then, we select a rule to execute, and create a new one.
The expression requires adding a new record to the Favorite vehicles entity, linking the Client as well as the vehicle added.
Thus we need to use the function Me.newCollectionItem as shown below.
var NewFav = Me.newCollectionItem("Addedtofavorites");
NewFav.setXPath("Client",Credential.Persona("Client"));
Notice that we only update the Client in the expression because the vehicle record will be automatically injected by Bizagi.
Create an action to remove a vehicle from Favorites
We need a button to display in the records of the vehicle that we have included in our Favorites collection. Thus, we will select the Favorite vehicles to be the one where the action is executed.
Then, we select a rule to execute, and create a new one.
The expression requires deleting an entire record from the Favorite vehicles entity. We need to use the function Me.deleteCollectionItems as shown below.
var ThisItem = Me.Context.getXPath("Id");
Me.deleteCollectionItems("Client.Favoritevehicles", Me.getXPath("Client.Favoritevehicles[id = "+ ThisItem +"]")
Last Updated 2/21/2023 9:35:14 PM