CRM 2011 – How do you associate an Email Template with Plugin command CreateWorkflowFromTemplateRequest?

I have a CRM 2011 plug-in that uses a CreateWorkflowFromTemplateRequest. This creates a new Workflow based on the Workflow template I have created in CRM. Inside my Workflow Template I have a “Send Email” step that uses a Corporate “Email template”. What I want to do is replace that Email template via code to another Template that a user has specified.
There doesn’t appear to be any properties I can modify against CreateWorkflowFromTemplateRequest to change this. In the CRM 2011 SDK it appears you have to generate the Workflow definition XAML and modify the Template ID. Has anyone had experience doing this? Any ideas how I can access the Workflow XAML inside a plug-in?

UPDATE 19th Jan 2011

Just a follow-up on this. My team was able to successfully modify the Workflow XAML property inside a plugin and replace the TemplateID Guid with the GUID of a Email Template we wanted to apply.

That was achieved using some standard text manupulation properties inside our plug-in
We were then able to save down the changes to the Workflow, Activate it and execute it against a CRM record without any issues.

This form of change to the XAML proved to be cumbersome and there are limitations. For example if you use more than one Email Template step in your Workflow, the plug-in code would overwrite all instances of “TemplateID” in your XAML.For our scenario we restricted the Workflows to only using a single Email Template to avoid this.

Give it a try! There may be some valid business reasons out there where you would want to change/overwrite an Workflow Email template at runtime…

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: