Help with arrays

Hi all

I’m trying to show a text summary of related values. A sale might have one related ‘main_group’ (eg Appliances), or it may have 10 related ‘main_groups’ (Appliances, Furniture, etc., etc., etc.). I need to generate a text field that says something like:

Appliances: GBP 2345.67
Furniture: GBP 3456.78
etc.: GBP 4567.89

There are a fixed number of 'main_group’s but not every record uses all of them.

I have been trying to do this using an array but am not sure of the syntax or how to get data out once I calculate it. The current incarnation of my array is:
var summaryarray = [sales_to_line_items.main_group]
return summaryarray;

This crashes Servoy.

Any pointers in the right direction would be appreciated. I’ve been trying for 2.5 hours now and am no closer to a solution…

Thanks

Bevil

var summaryarray = [sales_to_line_items.main_group] 
return summaryarray;

In what context do you use the above?

Following your code you define a new array with only one value in it at index 0, you then return the complete array. Is that what you intended to do?

Seems a bit strange to use an array here.
Also, check the relation you’re using since an empty relation may break your code:

var summaryarray = new Array()
if(utils.hasRecords(sales_to_line_items))
{
summaryarray = [sales_to_line_items.main_group]
}

return summaryarray;