Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

My issue is that Rebate Records are displayed in a different order than they were created. Let’s say I create records in this way: 1st, then 2nd, then 3rd. Then I use rebateRecords.getAll() and it returns 2nd, 3rd and then 1st. 

In our logic the user specifies which record is created first. If the user chooses that “A” must be created first and he saves the agreement then RRs are created. What about situation when user decides that he wants to have “A” created as the last record? The RRs created previously will be updated and their order will remain the same (so A will still be the first record from previous calculation).

What can I do to influence creation order?


Answer:

getAll() calls getRebateRecords() that enforces sort in search: sorting is based on the field RebateRecord.FIELD_RANK.

As for the creation order, RRs are created in the order in which your logic calls rebateRecords.add() method. If there is no RR for a line item, for the same rebate record set, with the same rebateRecordName, a new one us created, otherwise an existing one is updated.

rebateRecords.getAll() returns the records (for the given line item) sorted by rank, which you can set when creating the records. Rank is also used to determine the order in which the records are to be calculated. In other words, if order is of any importance, make sure to populate the rank attribute.

If it is just for viewing, you can also sort by ID or similarly in Groovy.

I set rank and this is creation order is working only for first calculation for given rebate agreement. It becomes more complex if I want to change creation order when there are already RRs calculated before. 

Records have ever increasing IDs, in the order of creation, so the order is deterministic.

  • No labels