Documents Core Pack comes with a useful “Create Document” button in enabled entities, where a pre-created template can be populated with data pulled from the fields on a Dynamics 365 record and its related records. When creating the template, conditional fields can even be inserted, which is a container that will only be visible if the condition is met.
We encountered a requirement where we wanted to be able to append another DCP template to a master template, if certain conditions were met. The two solutions we found to achieve this requirement are:
The choice depends on the individual requirements. The final merged document attained from the workflow option can be obtained via setting the automation to send emails. Whilst using the conditional fields will allow Users to use the Create Document button on entity forms, preview the final document and directly download it.
To merge documents via AutoMergeWorkingItems in a Dynamics 365 workflow, add a create step for the MSCRM-ADDONS.com AutoMergeWorkingItems entity.
Create each of the documents that you want to merge in a separate step, ensuring that the following AutoMergeAction is set to CreateDocument, choosing the template under the TemplateToExecute field. Ensure that everything under the General and Create Document sections are populated.
After the steps to create both documents, add another create step but this time choose Concatenate as the AutomergeAction, populate everything under the Concatenate section. Reference both created documents in the Document1GUID and Document2GUID fields.
If you would like this document attached to an email message record, add a create email step before all the document creation.
Reference it in the Email to Attach field under the Attach Email section.
Alternative to all of this, you can simply create an entire template with the contents of another template inside it, all within conditional blocks. You can do this by creating conditional fields like so and set your own custom condition.
You can then enter mailmerge fields inside this conditional block, which will appear only if the record this document is referencing meets those conditions.
Note that if a document uses a watermark or background image and you are looking to append this, simply place it within a conditional block and set it to Behind Text, Maintain Position on Page.
Having a background image, it can be difficult to position items around it. A trick I have found to make the formatting and positioning of each conditional block with its own mailmerge field easier, is to first create a text box like so.
Then insert the conditional block followed by the mailmerge field inside this text box. This way it is easier to move the object around to its correct position.