To merge Sub Clauses into a contract document, you must create a Nested SOQL Query and a Nested Detail Region, which allows you to merge repeating Clause data within another set of repeating Sub Clause data.

We recommend familiarizing yourself with Nested SOQL Queries before proceeding.

The following is an example of a Nested SOQL Query that gathers the basic information for Parent Definitions Clauses and their related Sub Clauses (filtered on a specific Contract Agreement record):

SELECT Id, APXT_Redlining__Text_Rich__c, APXT_Redlining__Order__c, (SELECT Id,  APXT_Redlining__Text_Rich__c, APXT_Redlining__Order__c FROM APXT_Redlining__Managed_Sub_Clauses__r ORDER BY APXT_Redlining__Order__c ASC )FROM APXT_Redlining__Managed_Clause__c WHERE APXT_Redlining__Contract_Agreement__c = ‘{pv0}’ AND APXT_Redlining__Clause_Type__c = ‘Definitions’ ORDER BY APXT_Redlining__Order__c ASC
CODE

Additionally, you need to create a Nested Detail Region in your agreement template to merge the data from the nested query. There are two ways to do this:

  1. Nested Merge Fields
  2. Nested Table

Nested Merge Fields

This is the recommended and simpler of the two options. Build out your template like the screenshot below:

In the above screenshot, notice the two sets of {{TableStart}} and {{TableEnd}} tags, one within the other. This is what makes it a Nested Detail Region. Upon merge, the corresponding nested SOQL Query populates the document with the two sets of repeating data.

A huge benefit with Nested Detail Regions is that it will remove the numbering for any parent clause that doesn’t have any sub clauses. This means you won’t have empty sub clauses, for example 1.2.1 with no text in it.

Lastly, in this example, the template is utilizing auto-numbering in Word, which dynamically numbers the Clauses and Sub Clauses (1.1, 1.1.1, 1.2, 1.3, etc.)

Nested Table

The Nested Table alternate method accomplishes the same output as the Nested Mergefields method, but uses a table in Word to do so.

In this scenario, we have a table with borders removed set up as the sub clause 1.1.1. The two columns are built such that the first column is as wide as the margins on the page, and the second column is outside of the margins. The second column will not show upon merge, and the first column will use up the entire printable space. If the sub clause query does not return any data, the row will be removed using Row Burner.

Using this method can be helpful if you are running into issues with the Nested Merge Fields not hiding empty sub clauses properly, or you have some strict formatting requirements that can only be accomplished in a Word table. In most cases, however, you will want to use the Nested Merge Field method.