# Document Consolidation



Document Consolidation is a feature that supports the creation of Policy Packets - a combination of multiple documents in a single, organized PDF.

Any document associated with the policy can be included in a policy packet, including any rendered externally and then attached to the policy or quote.

You can configure numerous policy packets, and leverage additional features such as a cover page, table of contents, and page numbering.

To do so, set up the top-level <ApiLink name="ConsolidatedDocumentConfigRef" /> configuration, adding the name of your consolidated document configuration to the `documents` set for applicable products' (<ApiLink name="ProductRef" />). The consolidated document trigger will match the latest trigger time of its subdocuments (those enumerated in the `consolidatedDocuments` array).

Subdocuments continue to be produced independently of the consolidated document, and can be fetched separately from the consolidated document.

Example [#example]

Suppose you have already defined a "WelcomePage" document and a "LegalDisclosures" document, and would like the two to be produced as a single "DocPackage" set. You would define "DocPackage" in <ApiLink name="ConsolidatedDocumentConfigRef" /> like this:

```json
{
	"DocPackage": {
		"consolidatedDocuments": ["WelcomePage", "LegalDisclosures"]
	}
}
```

And then add "DocPackage" to the applicable <ApiLink name="ProductRef" /> `documents` array:

```json
{
	"displayName": "Commercial Auto",
	// ...,
	"documents": ["WelcomePage", "LegalDisclosures", "DocPackage"]
	// ...,
}
```

You'll see the consolidated document produced as a distinct entity from its subdocuments, triggered at the same time as the latest trigger among the documents in its subdocument set (i.e., a consolidated document's trigger is inferred from its subdocuments).

If the above "DocPackage" set had been produced at quote issuance, you could expect to see a result like the following -- note that the consolidated document references the subdocuments, and each subdocument references the consolidated document in `consolidatedTo`:

```json
[
	{
		"locator": "01JT3P746EMZZ8J7KSMPQS36NZ",
		"referenceLocator": "01JT3P6QK4R4VXNJKR0TYRYZ1F",
		"referenceType": "quote",
		"staticName": "DocPackage",
		"documentInstanceState": "ready",
		// ...,
		"external": false,
		"consolidatedFrom": [
			"01JT3P6TNR1A0EWF5P83AEDJNG",
			"01JT3P6TNSTP758DG9CTV63PJZ"
		]
	},
	{
		"locator": "01JT3P6TNR1A0EWF5P83AEDJNG",
		"referenceLocator": "01JT3P6QK4R4VXNJKR0TYRYZ1F",
		// ...,
		"consolidatedTo": ["01JT3P746EMZZ8J7KSMPQS36NZ"]
	},
	{
		"locator": "01JT3P6TNSTP758DG9CTV63PJZ",
		"referenceLocator": "01JT3P6QK4R4VXNJKR0TYRYZ1F",
		// ...,
		"consolidatedTo": ["01JT3P746EMZZ8J7KSMPQS36NZ"]
	}
]
```

Notable Behavior and Limitations [#notable-behavior-and-limitations]

* The order that documents are listed in the `consolidatedDocuments` array is the order that they will appear in the consolidated document.
* The consolidated document will not be produced if none of its subdocuments are produced.
* If any of the candidate subdocuments are unavailable due to conditional rendering logic (i.e are suppressed in the document selection plugin), they will be skipped, with the consolidated document still be produced with the remaining subdocuments.
* If any of those candidate subdocuments are unavailable due to a rendering error, the consolidated document will not be produced.
