How can we use total function in HTML report

Posted by Sudhakar on 30-Jul-2014 13:46

Hi all,

i have created a Report with HTML type to get list of records in PDF (we are able to do this) format,at the bottom of PDF we need to total the Each column(we are not able to do this one)

As shown Above SS AD Today,Ad this week .... all are formula fields it will calculated the related action done from its related object.

Now my question is how can i get the values of the last row(Total) in PDF(that means in HTML report)

All Replies

Posted by Gian Torralba on 30-Jul-2014 14:24

Hi Sudhakar,

You can summarize the columns using EVAL blocks. Please refer to Chapter 6 page 160 of Rollbase in Action on how to use EVAL blocks. You can achieve this by creating/converting your fields to an expression field and then using the EVAL block to return the SUM of that column field. Formula fields cannot be used in queries so you need to convert it to an expression field.

#EVAL[rbv_api.selectNumber("SELECT SUM(expression_field_col) FROM object");] //This will be inside the <td> element in the report

Thanks,

Gian

Posted by Sudhakar on 30-Jul-2014 14:58

thanks [mention:c5dec1ce5a5948c5a25cf4bcaeb7db77:e9ed411860ed4f2ba0265705b8793d05] ,working perfect.

Posted by Sudhakar on 01-Aug-2014 11:25

Hi [mention:c5dec1ce5a5948c5a25cf4bcaeb7db77:e9ed411860ed4f2ba0265705b8793d05] ,

I have created expression fields to store AD Today,AD this week and etc as suggested by you,

But here im seeing strange behavior .for individual records it is showing correct values but im calculating Total by using EVAL function it is showing correct Data(total) based on individual values,but after some time it is not displaying correct values (i mean not calculating total based on  individual values).

if i update(no changes at all just open the expression and save it ) then it is displaying correct for that particular time

Kindly let me know how can i display total at  any time based on individual records with out update the expression field.

Posted by Gian Torralba on 04-Aug-2014 17:53

Hi Sudhakar,

When does the value on the expression field change? If the field changes based on the record update of other objects, you can add a trigger that will update the report record so that it is always updated. If you can provide a snippet of the code inside the expression field, that would be helpful in identifying what approach to use.

Thanks,

Gian

Posted by Sudhakar on 04-Aug-2014 18:19

Hi @Gian Torralba,

when over there is change in AD Today column values  then at the bottom total should calculate by taking those values.

Im using expression as below in referral source

if("{!status#code}"=="ACT") // if Referral source Status=Active

{

#CALC_COUNT.R101162498( 1 | createdAt>=TODAY) //count the no of "actions done"(related object to referral source)

}

And in HTML report im using as below

<td width="5%" align="center">#EVAL[rbv_api.selectNumber("SELECT SUM(ad_today) FROM referral_source");]</td>

Kindly let me know what i need to do to get dynamic total values at the bottom

Posted by pvorobie on 04-Aug-2014 18:30

One suggestion: I recommend always use /*  */ style comments instead of // style comments, this is much safer.

Posted by Sudhakar on 04-Aug-2014 18:43

thanks for suggestion [mention:05b5f00eae4a468d844fa8bedcafd110:e9ed411860ed4f2ba0265705b8793d05] ,

In live we are not using any comments,here i used comments in order to  others to make better understand.

Posted by Gian Torralba on 04-Aug-2014 18:48

Hi Sudhakar,

Thanks for the quick response. Here are two possible ways to get the dynamic values on the report.

Since expression fields doesn't update the values when the record is not updated and we still need to use the selectNumber API to compute the total, I suggest changing the expression field to an integer field and then creating an update field trigger on the related object that will update the integer field on create/update.

The second approach is that we stick to the expression field but instead of the update field trigger, you can use an object script trigger and the updateRecord API that will re update the record.

I would suggest using the first one since it will only update a single field rather than the whole record.

Thanks,

Gian

Posted by Sudhakar on 05-Aug-2014 11:54

HI @ Gian Torralba,

i have created trigger(Timing::After update,Type::Object Script--i need to update 4 fields at a time that why i have selected object scipt instead of update field value) as below

if("{!R101162498.status#code}"=="ACT")//if Referral source status=active

{

var a= rbv_api.selectNumber("SELECT SUM(ad_today) FROM referral_source");//ad_today is expression field to store single column value and not working as expected.if  i update the expression field then it is displaying as expected

rbv_api.setFieldValue("referral_source", {!R101162498.id}, "sum_ad_today", a);//sum_ad_today is integer field to store total at bottom,but not working as expected it is displaying Zero(i have updated a record in Action done and checked the value ) .

}

Posted by Gian Torralba on 06-Aug-2014 10:16

Hi Sudhakar,

If you are already using the integer field, you need to put the setFieldValue api trigger in object B. Since you are using a calc_sum on every added record in object B, you can set the trigger timing to on create so that it will update the field every time a record is added.

Thanks,

Gian

This thread is closed