How to check all the attributes of a list if they are equal and unify into one value in case they are all equal?

0
Hello everyone! I have a task where I should check all the attributes of a List, and for each attribute understand if all their values are equal then unify into one value. Example:  InstalmentList has attributes: Spec1, Spec2, Spec3, Spec4...Spec30 For each attribute they can have multiple values, example: Spec1: has Value1, Value2, Value3, Value4.   Now I need to check all the values for each attribute, and in case they are equal, unify them into one value. So if Value1=Value2=Value3=Value4, then present only Value1 for that specific attribute.   The challenge here is that can be more than 30 attributes with more than 3 values each, so does it mean I need to iterate over the InstalmentList for each attribute (mroe than 30 times)? Or is any other solution for this?
asked
1 answers
2

Hi Fjordi,

 

So you have several instalment objects and need to combine all these values as concatenated strings in a new object. If all the values for an attribute are the same you only want to display that one value, if they are not all the same, you want to show the list of all values.

 

Without being able to iterate over attributes of an entity, this is not going to be a nice solution, I'm afraid.

I would create a (non-persistable) helper entity that, for each attribute, stores two values: the 'value' as string and a boolean to indicate whether all values for that attribute so far have been the same.

 

On your first iteration, fill the helper object values with the values from the first instalment. Make sure all the booleans are true (do this by setting the default value in the domain model).

On subsequent iterations, check the value of the instalment against the stored value in the helper object and set the attribute boolean of the helperobject to:

if ($instalment/attribute = $helper/attributevalue) then

$helper/attributeboolean

else

false

 

After processing all instalments, use the helper object to set the final value:

if ($helper/attributeboolean) then

$helper/attributevalue

else

$newobject/attributevalue

 

answered