Avoid Returning Big Data in Element Result

Why

The calculations of some logics (mainly valid for line items, e.g. PGI, PLI) persist the calculation results into a system field (allCalculationResults). If an element returns big amount of data in the result, then persisting such a big field value for every item can cause serious problems in the database.

When to Use

Compared to Java, Groovy does not force you to use return statements. However, omitting this is not a recommended practice, since it can cause unexpected results. Imagine a situation that you do not need the element to return a value (e.g. because you only want to set api.global) and at the end of an element you leave an expression that is evaluated as a big list. It is strongly recommended to include a return statement at the end of each element, even if it is returning nothing. Also, if you return e.g. a List in some element as a temporary result, that element should have the Display option set to 'Never'.

def result = ... // some calculation return result

Explicitly including a return statement to all logic elements is recommended.

When Not to Use

There is no scenario where you would benefit from not adding an explicit return statement (even if it returns nothing).

Finally, we recently found out that large data sets being returned by logic elements can impact negatively the Pricefx instances processing the logic EVEN if the display option is set to 'Never'. This is because there is some data processing done BEFORE the display option check. Hence it is better to store the large data sets in api.global or api.local values instead of logic element results.

 





Found an issue in documentation? Write to us.