Count associated objects

0
Hi all. How can i retrieve the number of Aircargos objects that are associated to a specified Category? For example, if i insert in a text field as an input the Name (Like “Electronics”) of the Catagory, i’d like to directly retrieve the number of Aircargos associated to that Category (“Electronics”).
asked
4 answers
1

In the microflow retrieve over the association and use the aggregate List function to count. See documentation here: https://docs.mendix.com/refguide/aggregate-list

You can then use this value as return value of the microflow.

Regards,

Ronald

answered
1

Hi Matteo (Great Name!),

In order to this this the first step would be to do a database retrieve on Aircargo. In the xPath for this retrieve you have to use the association to Category and check if Aircargo_Category/Category/Name = ‘ Electronics’. This will return a list of all aircargo’s that are associated with the Electronics category.

 

Step 2 is to use the aggregate list activity. Open the activity and select the list you just made as List and select ‘Count’ as function. This will return an integer with the amount of items in the list. 


Please let me know if this works for you. 

answered
0

Hello Matteo,

Retrieve AirCargo over association by Category. Use a list operation to aggregate the retrieved list and do a count operation. It will give you the number.

For details take a look at Mx documentation:

https://docs.mendix.com/refguide/aggregate-list

answered
0
  1. You can use a microflow and in that Retrieve from database all the AirCargo objects where the Category name is the input name. Use an aggregate list activity to count the objects in that list. 
  2. If you already have the Category object with you then instead of DB retrieve, you can retrieve via association all the AirCargo objects associated with that Category object and then use an aggregate list activity to count the objects in that list. 
     

You have the count, now you can use it as per your requirement.

answered