Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Calculated merge fields allow you to use a scripting language (PHP) to perform calculations. Creating calculated merge fields is an advanced topic and requires a some understanding of computer programming and in particular PHP.  However it is fairly easy to create simple calculations by performing simple math on variables. 

Info

Note for security reasons only a limited subset of the PHP commands are available.

A calculated merge field is typically used when you need to add a new field to a document that is based on a calculation of existing fields. For example if you have designed a workflow for a property settlement you may need to calculate the rates apportionment on settlement day by dividing the amount already paid by how many days the new buyer will benefit from those rates after settlement day.  This amount usually gets added to the final amount payable at settlement.  This is easily achieved with a calculated merge field.

Creating a new calculated merge field

From the top navigation bar go to Admin / "Document Templates" / "List of Merge Fields". This will show a list of all available merge fields in the system.  

Tip
Tip: If you just want to see existing calculated merge fields then filter the list on "Data Source" = "Calculated Field".

...

Dates are stored in a universal notation in the database so you will need to use date functions to convert these to numbers before you can perform calculations on them, and then you will need to convert them back to strings to display them.  The online PHP manual has lots of good information on date functions.

Info

NOTE: you cannot create objects directly using the "new" operator. Instead you should use the object function aliases like date_create() instead of new DateTiime()

In this example let's say we have a property transaction action type in which we have created some custom data elements to capture details of the settlement. You want to produce a document that includes a calculation of how many days are left until settlement. To see the available custom data variables click on "View Available Variables + Data". In this example there is a custom data field represented by the array variable name $conv_settlement_data. The first element of the array contains the value 2014-10-15 00:00:00 which is the settlement date for the action ID we have choses to test with.

...

Code Block
$today = date_create();
$settlement = date_create($conv_settlement_settlement_date[1]);
$interval = date_diff($settlement, $today);
echo "There are " .  $interval->format('%d') . " day(s) left until settlement";
Info

NOTE: you cannot create objects directly using the "new" operator. Instead you should use the object function aliases like date_create() instead of new DateTiime()

...