The Musings of Chin - Template Formulas

From SmartWiki
Jump to: navigation, search

Chin's inaugural Musings entry provides a helpful rundown of Template Formulas and how they allow you to update field values on any object.

Let's learn about Template Formulas:


Template Formulas provide a method for updating standard or custom field values on an object behind the scenes upon saving. They let you perform extra calculations after saving an object. They can be handy because they let you:

  1. update an object and perform calculations after it has been saved (i.e. support ticket subjects, say you want to combine an autonumber field with the L1 subject but, when you first create the L1, the autonumber hasn't been reserved and stored yet until after you save).
  2. affect objects at different levels (i.e. a L2 formula can be used to update a L1, an L1 formula can be used to aggregate its contacts).
  3. easily perform difficult calculations with MySQL functionality and avoid heavy scripting (i.e. perform business day calculations).


The configuration settings can be found on most entities now, such as UTA L1, L2, L3, transactions, contact roles or company categories.


You must specify valid MySQL syntax within the settings box, and each line is ended with a semi-colon. Each line is processed sequentially and in order after saving an object.


Template Formulas run after an object is saved and uses the newly saved field values for their calculations. They are also chained such that when saving a L3 the formulas run in the order of L3 global formula, L3 type formula, L2 global formula, L2 type formula, L1 global formula, L1 type formula. When deleting a L3, the formulas for the L2 and L1 are also run.

Signs when they may be needed

  • When you have to save an object twice to get it to correctly calculate something.
Disclaimer: Template Formulas are run by the server, so for performance considerations should not be abused. 
A Template Formula should only be used when a calculation can not be achieved on the page with calculated value custom fields, or when trying to update a field that does not exist on the page (i.e. at L2 you wish to update a L1 field).

See Also