XPath for count

1
I need to get the count for each Enumeration value and display in  a text box. Below are the details: Entity name: NonConformance Enumeration: NC_Impact Enumeration values: None,Minor,Major,Critical  I have tried putting the below Xpath constraint in a ListView but get this error :   [Edit] I have created the microflow as suggested by Robin but where do i trigger this microflow? I tried calling the microflow from its attribute but got an error "Calculated value cannot be used for its own calculation” I also get an error when trying to make a many to one association NonConformance-NCRCount I have put a text widget in a dataview (NCRCount as datasource) with attribute parameter 'Minor Count’ and get above error.
asked
2 answers
2

If you want the best performing way, you should use an OQL-statement. Something like

SELECT count(*) as NumOfMinorOccurences, NC_IMPACT
FROM NonConformance
GROUP BY NC_Impact

https://docs.mendix.com/refguide/oql#1-introduction

answered
4

You can only retrieve and show data if you use an xpath datasource on a list view widget.

What you could do is create a new entity (i.e. NonConformanceCounter) with an integer attribute in which you will store the counted value and use a microflow datasource to create this entity.

In the microflow you should add the following actions:

  1. Retrieve list from DB of the NonConformance entity filted based on your enum value.
  2. Aggregate list action → Count the NonConformanceList
  3. Create new object of the newly created NonConformanceCounter entity and write the count value to the integer attribute.
  4. In the end event specify your NewNonConformanceCounter entity as the return value

 

Don't forget to set the proper access rights.

Based on the limited information provided i'd opt for a non persitent entity.

answered