Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Document Template Generation in Plugin

$
0
0

Hi,

I generate a document template in a plugin like this and it works well;

            OrganizationRequest req = new OrganizationRequest("SetWordTemplate");

            req["Target"] = new EntityReference(entity.LogicalName, entity.Id);
            req["SelectedTemplate"] = new EntityReference(documentTemplate.LogicalName, documentTemplate.Id);

            context.OrganizationService.Execute(req);

This gets attached to my entity and I can open it.  I have a problem when I try and attach this generated document to an email. It will not open and says the document is corrupted. Perhaps the mime type is wrong?  I use the following code and the mime type is application/octet-stream which I think is the type for the note, not the attachment.

            Entity attachement = new Entity("activitymimeattachment");
            attachement["body"] = document.Attributes["documentbody"];
            attachement["filename"] = document.Attributes["filename"];
            attachement["objectid"] = new EntityReference("email", emailId);
            attachement["objecttypecode"] = "email";
            attachement["mimetype"] = document.Attributes["mimetype"];

            context.OrganizationService.Create(attachement);

How can I attach this document (retrieved via fetchXML) to an email and have it open correctly?

Thanks for any pointers.

EDIT:  Further debugging shows that my query to get the latest document returns a very small amount of data for 'documentbody'.  It feels like maybe the SetWordTemplate has created the document but is running asynchronously and hasn't finished creating the document yet? Any ideas would be great!


Viewing all articles
Browse latest Browse all 46379

Trending Articles