Using Logic and Conditionals When Generating Documents

Sending a well crafted thank you letter to your donors is an essential part of your non-profit’s fundraising efforts. Acknowledging a donor in a timely manner increases giving and also improves donor retention. And when you need to send large numbers of such letters, you would want to automate the process so that members of your staff can send them off with a couple of clicks. This is when you need Apsona’s Document Generator to set up the process seamlessly.

A use case – Consider a scenario where you need to send your donors a thank you letter after a successful campaign. In this case, the content or the body of the letter is the same for all donors, but the signatures on the letters are determined by the donation amount. Donors who have donated $500 or more get a thank-you letter signed by the President of the organization. Those who have donated between $250 and $500 get letters signed by the Executive Director, and donors who have given under $250 get a letter signed by the Philanthropy Officer.

Setup – Setting up the merge with Apsona’s Document generator is a four-step process: Create a template, creating the data sources for the template, map your data, and generate documents. As the body of the letter is the same for all the donors, the template will only need to have the required merge fields or place-holders for the relevant data to be filled in. With Apsona’s support for conditional directives (i.e., if-then-else), you can selectively include or exclude content in your document based on data conditions. In the use case we are looking at, it is the different signatures on the letters determined by the donation amount.

template1

In the above template, we have just four merge fields as place-holders: First name (Donor name), Donation amount, date the payment was received and the Household name. The data for the merge fields are available in the Contact object, and the data for the merge fields in the body are available in the Opportunity object, and the two are linked via the Primary Contact lookup in the Opportunity object. So you can create a simple Opportunity report that extracts all the necessary data fields to generate this document.

The signature area contains conditional directives to drive the logic outlined above:

«IF Opportunity_Amount>=500»John Doe
President«ELSE IF Opportunity_Amount>=250»Jane Doe
Executive Director«ELSE IF Opportunity_Amount>=100»Jill Doe
Philanthropic Officer
«ELSE»John Doe
President «ENDIF»

In the above example, we use four directives, IF, ELSE IF, ELSE and ENDIF, to provide the logic. Each directive is created as a standard Word merge field. The code in the above example looks for the template field Opportunity_Amount. The text of the signature is interspersed with the directives so that the required logic is implemented.

It is important to ensure that each IF directive must be followed at some later point by a corresponding ENDIF directive so that the text segments that produce the signatures are clearly differentiated from the main body of the document. The document generator checks for this condition, and if a violation is detected, it might produce an error message like the one below.

IF

The example here shows the If – Then – Else conditionals in the signature are of the letter but you can get really creative and use it from the address and body of the letter as well. Detailed documentation on the If -then- Else conditionals is available on the Apsona website. Here is the link.