Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Question

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.

Answer

The method rebateRecords.getAll() returns records (for the given line item) sorted by rank (field RebateRecord.FIELD_RANK) which you can set when creating the records. Rank is also used to determine the order in which the records should be calculated.

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

As for the creation order,  RRs 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 Rebate Record set, with the same rebateRecordName, a new one us is 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.

...

hiddentrue

...