Related Fields Totalling

Posted by eric@allwestern.com on 22-May-2017 19:53

Can a related field (currency for example) be totalled inside a report or list view? 

All Replies

Posted by Shivani Silveri on 23-May-2017 06:29

Hi Eric,

The related field cannot be used for totaling. You could use an Expression field to achieve this.

Could you let us know the scenario that you are trying to achieve?

Thanks,

Shivani.

Posted by Shiva Duriseati on 23-May-2017 08:27

Hi Eric,

You could use following code in HTML template report to get the sum of all related field(Currency type) for each record.

Example:

I have created two objects ObjectOne and ObjectTwo with 1-1 cardinality . Created "Currency Field" in ObjectTwo ,used related field in ObjectOne as "Currency Field". In HTML template report used following code. Please note there could be another way to do this.I have used simple method by looping all the records in "ObjectOne" and summed up related fields(currency fields).

<html>

<head>

<script>

function sum() {

var sum=0;

{!#LOOP_BEGIN.all#XqYfrWJQQZuyp-T-PaxH1Q}

var number = Number("{!relatedfield}".replace(/[^0-9\.]+/g,""));

console.log(number);

sum=sum+parseFloat(number);

{!#LOOP_END.all}

document.getElementById('id').innerHTML = sum;

}

</script>

</head>

<body onload="sum()">

<span id="id"></span>

</body>

</html>

 

Please find attached app.xml for your reference.

Regards,

Shiva

[View:/cfs-file/__key/communityserver-discussions-components-files/25/SampleCurrencyApp_5F00_v2.xml:320:240]

This thread is closed