neutrino36
(neutrino neutrino)
October 28, 2019, 8:42pm
#1
Hello,
Is there any possibility to have access to the aggregation values from a table?
Let say we have a column with BigDecimal values and following the aggregation “SUM” we have a top row with a BigDecimal value: 524.
How can we get 524 programmatically?
Regards,
-n
tsarev
(Daniil Tsaryov)
October 29, 2019, 5:31am
#3
Hello @neutrino
You can use method Table#getAggregationResults()
that returns map of aggregation results for corresponding columns.
Regards,
Daniil
1 Like
neutrino36
(neutrino neutrino)
October 29, 2019, 2:36pm
#6
Something doesn’t work…instead of 75 I have 0.
for (int i=0; i<resourcesTable.getAggregationResults().size(); i++){
Map<Object, Object> hash = resourcesTable.getAggregationResults();
Set<Object> set = hash.keySet();
Iterator itr = set.iterator();
Object string = itr.next();
BigDecimal val = (BigDecimal) hash.get(string);
System.out.println("jjj" + string );
System.out.println("fff" + val);
}
tsarev
(Daniil Tsaryov)
October 30, 2019, 5:52am
#7
Could you describe the case in more details? I’ve tested all aggregation types with BigDecimal
and everything works ok.
neutrino36
(neutrino neutrino)
October 30, 2019, 6:07am
#8
I defined a new BigDecimal attributeamount
(to a random entity), I set the aggregate type (table and column) and I tried to get the SUM result to onInit
method. In the map there is amount
attribute but the value is zero.
Maybe I have to define more columns? But is non sense…
Can you share your code snippet, please?
tsarev
(Daniil Tsaryov)
October 30, 2019, 6:12am
#9
You cannot get aggregation results because at this moment there is no data to aggregate.
neutrino36
(neutrino neutrino)
October 30, 2019, 6:15am
#10
I don’t understand. I added 3 records (40, 30, 5) and the table shows aggregate 75. What do you mean…
there is no data?
tsarev
(Daniil Tsaryov)
October 30, 2019, 6:29am
#11
I mean that data is not loaded when InitEvent
occurred
neutrino36
(neutrino neutrino)
October 30, 2019, 6:33am
#12
Why?
From which event the data is loaded? I tried to AfterInitEvent
but the result is the same.
tsarev
(Daniil Tsaryov)
October 30, 2019, 6:38am
#13
In generic case @LoadDataBeforeShow
annotation is used, so you can subscrube for BeforeShowEvent
when data will be ready
neutrino36
(neutrino neutrino)
October 30, 2019, 6:45am
#14
Still doesn’t work:
@Subscribe
public void onBeforeShowEvent(BeforeShowEvent event){
//my code
}
Where shoud I use @LoadDataBeforeShow
annotation?
tsarev
(Daniil Tsaryov)
October 30, 2019, 6:59am
#15
Sorry, I’ve mixed up with AfterShowEvent
:
neutrino36
(neutrino neutrino)
October 30, 2019, 7:11am
#16
It works perfectly now.
You made my day!
Thank you Daniil!