Sep 17, 2019

Programmatically populate Word Document Template

Ability to use Word document templates is one of the very useful features in Dynamics 365.

Here it is explained how to do it without any complicated steps.

Anyway, sometimes we may need to populate these templates programmatically. Below is the code snippet to do that using SetWordTemplate message.

OrganizationRequest req = new OrganizationRequest("SetWordTemplate");
req["Target"] = new EntityReference("account", new Guid("aaa19cdd-88df-e311-b8e5-6c3be5a8b200"));
req["SelectedTemplate"] = new EntityReference("documenttemplate", new Guid("9d6916e4-1033-4e03-a0e3-d15a5b133a9a"));
//if its a personal Template
//req["SelectedTemplate"] = new EntityReference("personaldocumenttemplate", new Guid("262032ac-13d9-e911-a975-000d3a37f8b9"));
svc.ExecuteCrmOrganizationRequest(req);

Anyway, this message manages to create the Document and attach to the relevant record as a Note. If its required to use this for other way, it may need to retrieve the document from the Note.

No comments:

Post a Comment