Total Currency values on a related list

George Z
Tera Contributor

I have 4 currency fields on an incident form under a related list.  I would like to total the Cost+Shipping+Tax and show the  Total (auto-calculated).  Is there any way to do this without having to code it?  Not against code just not too great at it.  If that's the only way I would need step-by-step help.  Any help is much appreciated. 

1 REPLY 1

Aylee Andersen
Kilo Sage

Hi @George Z!

 

Unfortunately, I don't think there's a way to auto-calculate the total without using code. The only way I can think of to do it without code is to use Flow Designer, but I think I would still recommend a classic Business Rule for this. If you would rather have it be in Flow Designer, you could do that, but this Business Rule would be pretty simple. Here is how I would set up my Business Rule:

 

When to run:

  • Insert & Update
  • Before
  • Filter Conditions - Total is empty OR Cost changes OR Shipping changes OR Tax changes

Advanced (script):

(function executeRule(current, previous /*null when async*/) {

    /**
     * current.getValue('fieldName') will return the value stored inside that specific field (use the field name, not the field label)
     * 
     * parseFloat turns the value into a number instead of a string/text
     */
	current.total = parseFloat(current.getValue('cost')) + parseFloat(current.getValue('shipping')) + parseFloat(curent.getValue('tax'));

})(current, previous);

 

If you wanted the total to be calculated while a user is typing in the Cost, Shipping, or Tax fields instead of when they save they record, you would need to do that via a Client Scripts. But this Business Rule should do the trick if you just want it calculated when they save the record.

 

Hope that helps!

- Aylee