ms crm 365 / fill word template with data and create word document programmatically c#

1.6k Views Asked by At

dcrm 365 has a feature to create word documents using word templates. I want to use this feature in c#, for example, I have my Invoice entity and the documenttemplate entity. I want to create the result Word document. is this something that ms crm should handle, eg with a service request or so, or should I do it with a third part library or ...

any direction would be helpful

1

There are 1 best solutions below

2
On

SetWordTemplate is the message which generates a word document based on the provided template and attaches the generated document to the Note regarding the Target entity.

OrganizationRequest req = new OrganizationRequest("SetWordTemplate");

req["Target"] = new EntityReference("theEntity", theGuid);
req["SelectedTemplate"] = new EntityReference("documenttemplate", templateGuid);

service.ExecuteCrmOrganizationRequest(req);

The hassle is, since the document will be attached to a Note you have to recover it with a separate Retrieve.

The exact same is available as an Action in a Workflow, add step Execute Action > SetWordTemplate (not 100% sure about the exact wording, it eludes me atm). Same as above, it creates a Note.