Calculated fields can be created against document template tags to format document-related data. For example, you can use calculated fields to vary the content of the subject line of a letter or email, depending on the type of recipient of the communication. You could also use them to format the user responses on a form builder questionnaire used in a prepare document or email template.
To create a document calculated field, follow these steps:
- Navigate to Doc Admin in ShareDo by navigating to Launchpad > Open Documents Admin.
- Open the document template that you wish to add the field to by selecting Document Templates from the left-hand menu. For the purposes of our examples below, select a letter template that has a recipient.
- Now, open the Tag Browser
from the ribbon bar.
- Select the Document set of tags. We can now create a calculated field against any of these document actions.
For more information, see Creating a Calculated Field.
Example 1
In this example, we'll create a calculated field that returns the name of the recipient’s employer where the recipient is an employee rather than an individual. This tag can be used to help build up the title of the generated document.
For example, use the tag to make the document title Letter to ABC Insurance re Initial Response, rather than Letter to John Sample re Initial Response, where John Sample is the recipient and an employee of ABC Insurance.
- From the tag list, select Document Recipient.
- Create a calculated field by clicking the
to open the expression editor and call it RecipientName. Then add the following expression:
if($root.document.recipient.contextParticipant.ods.person.connections.employer!1.organisation.name <> null, $root.document.recipient.contextParticipant.ods.person.connections.employer!1.organisation.name, $root.document.recipient.contextParticipant.ods.name)
This expression checks to see if the recipient has an employer connection and, if so, returns the employer's name.
Before saving, consider the Context option:
Should this calculated field be available for every document template or just for this one? Tick the Is global for all doc-gen types box, as appropriate. - Click Save & Close to continue.
The field is now available at the foot of the Document Recipient section under Calculated Fields for this document template (and all documents if the context option above was ticked):
It can be used in the Output Title of the Pack Contents blade:
Example 2
This example varies the subject line of a letter or email depending on the type of recipient.
- Select a template that has a recipient. Navigate to the Tag Browser.
- Open the Documents tags and navigate to Document Recipient > Context Participant.
This level contains the details of the person to whom the user is writing – including their role on the current work item. - Create a calculated field by clicking the
to open the expression editor and call it LetterSubject. Then add the following expression:
if(contains(pluck(roles, 'roleType.systemName'), 'client'), 'Your Claim',
'Our Client: ' + $root.context.roles.client.ods.name)
This tag will hydrate with the text “Your Claim” if writing to the client, otherwise, it will return the text “Our Client: ” followed by the client name.
This can be extended to check for different roles and vary the text and/or call other calculated fields to set the subject text.
Before saving, consider the Context option:
Should this calculated field be available for every document template or just for this one? Tick the Is global for all doc-gen types box, as appropriate. - Click Save & Close to continue.
The field is now available at the foot of the Context Participant section under Calculated Fields for this document template (and all documents if the context option was ticked):
Example 3
This example creates a calculated field that formats the date of a Date field on a Prepare Document Questionnaire.
- Select a template that contains a Document Questionnaire with a Date field.
- As in the examples above, navigate to the Documents tags in the Tag Browser.
A Questionnaire tag section is displayed:
Open this. A calculated field can be created against any tag here. - Create a calculated field by clicking the
to open the expression editor and call it FormattedDate. Then add the following expression:
format([name of date tag], 'ddos MMMM yyyy')
(replace the text in bold with the actual name of the date tag).
Before saving, consider the Context option:
Should this calculated field be available for every document template or just for this one? Tick the Is global for all doc-gen types box, as appropriate. - Click Save & Close to continue.
This calculated field can now be used in documents and emails where the form builder questionnaire is also used. It will format the date the user enters into the questionnaire to include the date ordinal (e.g, 21st December 2023).