Adding business logic

After an application contains the appropriate objects and relationships to capture data, you will likely want to add logic that uses or transforms that data. Platform supports this through templates and formulas. Templates allow you to define a structure for calculating and displaying information. Templates contain tokens, which are variables that the runtime replaces with values from the object currently in scope. Formulas are interpreted as Javascript expressions, they describe how to calculate values. If a template contains formulas, the runtime first parses the merge tokens to obtain the values. Once the values are obtained, the runtime evaluates the Javascript expressions using the appropriate values.

For example, suppose an object contains fields for quantity and price and you want to calculate the price of a particular quantity. Using the tokens, {!quantity} and {!price}, which correspond to fields in the relevant object, the runtime will handle them in a formula as follows:

  • Formula: {!quantity} * {!price}>
  • Parsed formula values evaluated as Javascript: 100.0 * 5
  • Result: 500

The following table describes the areas of a Platform application where you can use templates and formulas and why you might use them.

Templates Where and How Used Formulas Where and How Used
Page HTML and Script components Create in page editor Object formula fields Object definition
Object template fields and integration links Create in Object definition Trigger conditions and expressions Part of trigger definition that determines when trigger will run or what value to use as a result
Object Record Name Template Object definition to automatically generate record names Workflow action conditions Part of workflow definition that determines whether workflow should proceed
Mail Templates Object and workflow definitions to dynamically generate e-mails Field validation conditions Object field definition
Document Templates Workflows, template-based reports, and Document Template fields to dynamically generate documents Values calculated in gauges Part of gauge definition to calculate values to render in the gauge
Report Templates Report definition to dynamically generate reports EVAL blocks In non-formula templates, such as email or document, use to embed a formula