0

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

Muhammad Naderi
  • 3,090
  • 3
  • 24
  • 37
  • [this](https://stackoverflow.com/questions/27546926/generate-mail-merge-documents-programatically-on-microsoft-dynamics-crm-2013) seems similar question which is already marked as answered. – Sandeep Apr 24 '18 at 14:30
  • These are different features of dcrm, my question is about Document Template, while your link is about Mail Merge Feature – Muhammad Naderi Apr 24 '18 at 14:33

1 Answers1

0

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.

Alex
  • 23,004
  • 4
  • 39
  • 73