# Quick Question on Calculated Rollups Fields from Child Objec

Posted by intekra on 17-Jun-2016 10:39

Good Day All,

I am trying to add a rollup field to a parent object (Invoices) to sum up the total of each line item on the child object (invoice line items). Can't seem to roll up this "total" calculated field on the child object to a grand total on the parent object. Tried roll up summary field, but that calculated child field wasn't an option... Do I have to do a formula field with javascript?

Thanks

Jeff

Posted by Dr Ganesh Iyer on 17-Jun-2016 14:08

Yes. you are right. You have to do a formula field with JavaScript.

An example as below:

Create a formula field (Decimal) say "Invoice".  and the code snippet to be used there is:

var totalInvoice = 0;

{!#LOOP_BEGIN.R241825084}

totalInvoice += {!Percentage};

{!#LOOP_END.R241825084}

In this example script, R241825084 is the "relationship Name" of the child and {1Percentage} is the field in child object which I want the sum to be rolled up.

Hope this helps!

#### All Replies

Posted by Dr Ganesh Iyer on 17-Jun-2016 14:08

Yes. you are right. You have to do a formula field with JavaScript.

An example as below:

Create a formula field (Decimal) say "Invoice".  and the code snippet to be used there is:

var totalInvoice = 0;

{!#LOOP_BEGIN.R241825084}

totalInvoice += {!Percentage};

{!#LOOP_END.R241825084}

In this example script, R241825084 is the "relationship Name" of the child and {1Percentage} is the field in child object which I want the sum to be rolled up.

Hope this helps!

Posted by Ricardo Rafols on 17-Jun-2016 14:45

Hi intekra,

To enable the roll up field, you need first to establish a relationship between the objects..

After creating the relationship the field Roll up shows up in the list of available field type.

When selecting roll up field, the next option is to select witch relationship, field and computation will be used to calculate this field.

When selecting SUM, Rollbase creates a formula field with following code:

#CALC_SUM.R9367(Amount)

Where R9367 is the relationship name and Amount is the field in the child object.

After attaching child records to parent record, the new create field will show the SUM of the Amount field from the child records.

Posted by intekra on 17-Jun-2016 14:51

Thanks Dr Ganesh! Worked perfect!

Posted by intekra on 17-Jun-2016 14:53

Ricardo, I tried your way initially last week and it didn't work as the field I am rolling up is also a calculated field. But the javascript way worked for me noted by Dr Ganesh.

Thanks Guys.

Jeff

Posted by Ricardo Rafols on 20-Jun-2016 06:50
Hi intekra,

Just in case, I’m attaching my test XML APP for your analysis.

Regards,
Ricardo

Posted by intekra on 20-Jun-2016 08:25

Thanks Ricardo.

Dr Ganesh & Ricardo, one more quick question on the rollup. How do I go about adding a filter to the javascript so I only rollup certain records. For example, all the line items with a pickilst field = a certain value...

Thanks

Jeff

Posted by Ricardo Rafols on 21-Jun-2016 08:42

Hi Jeff,

The syntax is:

#CALC_SUM.<relationship>( expression | condition ) or

#CALC_SUM.<field>( expression | condition )

The link below points you to the documentation:

documentation.progress.com/.../

Regards,

Ricardo

Posted by intekra on 23-Jun-2016 13:42

Thank you Ricardo, I seem to be still having an issue and can't wrap my head around this...

I have two objects Invoice and invoice line item. I need to SUM all of the "Hours" for all the line item records and display this field on the invoice object. However, I need to add a conditions for a file don invoice line item that Type (Picklist) value = "Consulting".

I'm trying this but doesn't work...

#CALC_SUM.R240954946 ( Hours | Type = "Consulting" )

R240954946 is my relationship name to invoice line items..

Below works fine and rollups up proper total of hours...

#CALC_SUM.R240954946(Hours)

But I need to add the condition to filter out values...