Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
You can download the latest source code at:
In this scenario we have used Aspose.Words.dll
to generate document from a template. We have defined a custom workflow assembly that can be used with Workflows and Dialogs in CRM.
[RequiredArgument]
[Input("Document Template")]
[ReferenceTarget("aspose_documenttemplate")]
public InArgument<EntityReference> DocumentTemplateId { get; set; }
[Output("Attachment")]
[ReferenceTarget("annotation")]
public OutArgument<EntityReference> OutputAttachmentId { get; set; }
byte[] DocumentBody = Convert.FromBase64String(Note["documentbody"].ToString());
MemoryStream fileStream = new MemoryStream(DocumentBody);
Document doc = new Document(fileStream);
string[] fields = doc.MailMerge.GetFieldNames();
string[] values = new string[fields.Length];
for (int i = 0; i < fields.Length; i++)
{
if (PrimaryEntity.Contains(fields[i]))
{
if (PrimaryEntity[fields[i]].GetType() == typeof(OptionSetValue))
values[i] = PrimaryEntity.FormattedValues[fields[i]].ToString();
else if (PrimaryEntity[fields[i]].GetType() == typeof(EntityReference))
values[i] = ((EntityReference)PrimaryEntity[fields[i]]).Name;
else
values[i] = PrimaryEntity[fields[i]].ToString();
}
else
values[i] = "";
}
doc.MailMerge.Execute(fields, values);
MemoryStream UpdateDoc = new MemoryStream();
doc.Save(UpdateDoc, SaveFormat.Docx);
// The `SaveFormat` is assigned on the basis of Input Parameters.
Entity NewNote = new Entity("annotation");
NewNote.Attributes.Add("objectid", new EntityReference(PrimaryEntityName, PrimaryEntityId));
NewNote.Attributes.Add("subject", FileName != "" ? FileName : "Aspose .NET AutoMerge Created Document." + saveAs);
NewNote.Attributes.Add("documentbody", encodedData);
// Set the type of attachment
NewNote.Attributes.Add("mimetype", @"application/vnd.openxmlformats-officedocument.wordprocessingml.document");
NewNote.Attributes.Add("notetext", "Document Created using template");
// Set the File Name
NewNote.Attributes.Add("filename", FileName != "" ? FileName : "Aspose .NET AutoMerge Created Document." + saveAs);
Guid NewNoteId = service.Create(NewNote);
OutputAttachmentId.Set(executionContext, new EntityReference("annotation", NewNoteId));
Please Note: This Add-on is Open source. The Scenario we have created and resolved the issue may differ from the end user. You can download the latest source code and update it according to your business needs.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.