Skip to content

Building an Automation (Part 4 – Coding the Documents)

hire a robot

This is the fourth of a series of articles that will examine the building process behind a document automation solution. The first article in the series (First Steps) is here, the second article (Document Review) is here, and the third article (The Form) is here.

Field Names

Every answer in the form will be identifiable by its ‘field name’. For example, the File Reference (the first question on the form) is identifiable by its field name, which is FileRef. (Some form builders allow you to edit the field names, some don’t).

Some answers in the form can be manipulated, or selectively used, by adding some additional instructions to the field name. For example, the ‘Donor’s Name’ field is called DonorDetails.Name. However, the user will have inputted a ‘First Name’ and a ‘Last Name’, and so we can use additional instructions to call up specific details:

  • Donor’s First Name = DonorDetails.Name.First
  • Donor’s Last Name = DonorDetails.Name.Last

Lifting information from the form and dropping it into a document is pretty straightforward.

However, we want some ‘intelligence’ baked into the system, which is where conditional formatting comes in.

Conditional Formatting

Conditional formatting, as far as I am concerned for the purpose of this piece, is a means by which the content of the outputted document can be altered depending on whether certain conditions are met.

To use a straightforward example – if the user of the form tells me that there is only one Attorney making the registration application, then I need to generate a Grounding Affidavit in the voice of a single Attorney (using singular pronouns) and to be sworn by that single Attorney. If, however, the user tells me that there is more than one Attorney making the application, then the Grounding Affidavit needs to be in the voice of multiple Attorneys (using plural pronouns) and to be sworn by each of those Attorneys (however many there may be).

The main tools I will use for conditional formatting are: (1) The ‘if’ statement, and (2) The ‘foreach’ loop.

The ‘if’ statement

This is a way of telling the document: “If condition [a] is satisfied, do [b]”.

You can also issue instructions as to what is to happen if condition [a] is not satisfied.

An ‘if’ statement can include as many conditions (and resulting instructions) as you wish. Arguably the key is to keep it as simple as possible.

An ‘if’ statement can affect as much or as little of the document as you wish – you can use one to simply add an ‘s’ at the end of certain words (to make them plural instead of singular), or you can use one to insert/remove multiple paragraphs or pages.

The ‘foreach’ loop

This is used where there is an undetermined number of data points – in our example we don’t know how many Attorneys will be named as applicants. There will be at least one, and our form allows for as many additional applicant Attorneys as may be necessary.

The ‘foreach’ loop tells the document: “For each [item], do [instruction]”.

The [instruction] that is executed can be as short or as long as you wish.

Example: Grounding Affidavit

Our Grounding Affidavit will need to be entitled “Affidavit of [Applicant Attorneys]” and I need the system to figure out:

  • Whether there is one or several Applicant Attorneys;
  • If there is one, insert that name only;
  • If there are several, insert all relevant names.

Let’s take a look at how we would do that.

We know that there has to be at least one Attorney, so let’s put that name in first:

AFFIDAVIT OF {$ApplicantAttorney.Name.FirstAndLast|upper}

(Translation: After the words ‘AFFIDAVIT OF ‘, insert the full name of the Applicant Attorney and convert all letters to upper-case.)

To find out whether there is one or several Attorneys, we can look at the form.

There is a question on the form about whether more than one Attorney is making the application. The answer to this question (which has a field name of ‘AdditionalApplicantYN’) will tell us what we need to know, and we can use an ‘if’ statement to tell the document what is to happen:

{if $AdditionalApplicantYN == "1"}[DO THIS]{/if}

(Translation: If the answer to the question is ‘yes’, [DO THIS]. – Note that nothing will happen if the condition is not met, as we have not given any instructions for that eventuality.)

In order to tell the document what to do ([DO THIS]), we will use a ‘foreach’ loop:

{foreach from=$AdditionalApplicant item=_AdditionalApplicantAttorney}[INSERT INFO]{/foreach}

(Translation: Please run a ‘foreach’ loop on the $AdditionalApplicant section, selecting each Additional Applicant as an individual item.)

Within the ‘foreach’ loop we need to tell the document what to insert [INSERT INFO]:

and {$_AdditionalApplicantAttorney.Name.FirstAndLast|upper}

(Translation: For each Additional Attorney, add a space, the word ‘and’, another space, and the Attorney’s full name and convert the letters of the name to upper case.)

The code for the title of the Grounding Affidavit, then, is:

AFFIDAVIT OF {$ApplicantAttorney.Name.FirstAndLast|upper}{if $AdditionalApplicantYN == "1"}{foreach from=$AdditionalApplicant item=_AdditionalApplicantAttorney} and {$_AdditionalApplicantAttorney.Name.FirstAndLast|upper}{/foreach}{/if}

This looks pretty horrible in the document template but it works, and when the document is generated all of the code will disappear and leave a lovely, formatted, capitalised title in its place.

Building the Documents

If all of the above looks pretty complicated to you, that’s because it is!

We’ve only dealt with a few functions (‘if’, ‘foreach’, ‘upper’) and there are many, many more.

The good news is that it is completely logical, and the even better news is that the functions are well documented online for your perusal. (For example, see this Smarty Documentation in relation to ‘if’ statements.)

For our EPA Registration System, you will recall, we need to build the following documents:

  • Notice of Intention to Apply for Registration (addressed to Donor)
  • Covering Letter addressed to Donor
  • Notices of Intention to Apply for Registration (addressed to each Notice Party)
  • Covering Letters addressed to each Notice Party
  • Notices of Intention to Apply for Registration (addressed to each Non-Applicant Attorney)
  • Covering Letters addressed to each Non-Applicant Attorney
  • Notice of Intention to Apply for Registration (addressed to Registrar of Wards of Court)
  • Covering Letter addressed to Registrar of Wards of Court
  • Affidavit of Service of Notices of Intention to Apply for Registration
  • Application for Registration
  • Covering Letter addressed to Donor
  • Covering Letters addressed to each Notice Party
  • Covering Letters addressed to each Non-Applicant Attorney
  • Affidavit of Service of Application for Registration
  • Grounding Affidavit
  • Covering Letter addressed to Registrar of Wards of Court

Some of the complicating factors that may arise (and which will need to be dealt with by conditional formatting) are:

  • Whether the Donor continues to reside at EPA address and, if not, what information the documents should contain;
  • How many Notice Parties there are/were, whether their present address is known, and where their respective Notices and Letters should be directed (and how should they be dealt with in the Grounding Affidavit and the Affidavits of Service if their present address is not known?);
  • Same considerations in respect of the Non-Applicant Attorneys.

Thankfully, with the application of logic to each of these potential problems, a document set can be created that responds to each of the above eventualities and generates a completed set of documents based on the instructions inputted in the form.

The EPA Registration System is now built and ready for you to test. If you’re curious to see it in action then get in touch with me and I’ll tell you where you can view it.