web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Create email in Workflow (but do not send it) using a Template

(0) ShareShare
ReportReport
Posted on by

I need to Create an Email in a Workflow but do not send it, since I need to add dynamic recipients to that email. The problem is I need to Create that Email using a Template. Do you know how can I accomplish that?

Thank you.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Thomas David Dayman Profile Picture
    11,323 on at

    In your workflow:

    1. Add Step
    2. Send Email
    3. Use Template

    You will need to add the email template in your crm before you create the workflow

  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    Hi,

     I think you'll need a custom workflow activity which will use InstantiateTemplateRequest:

    msdn.microsoft.com/.../hh210212.aspx

     You will have that email in the EntityCollection of the response:

    msdn.microsoft.com/.../microsoft.crm.sdk.messages.instantiatetemplateresponse.aspx

  • Suggested answer
    prt33k Profile Picture
    6,907 on at

    This wont be possible using OOB workflow since you dont have to send the email.

    Create a custom workflow which will create email with template and there you can populate the dynamics recipients as well.

    blogs.msdn.microsoft.com/.../send-mail-to-team-using-custom-workflow-activities-in-crm-20132015

    Thanks,

    Prateek

  • Euclides Pelisco Jr Profile Picture
    133 on at

    Vicent Rico 

    Hi, did you accomplished this? I have the same scenario but having hard time on having my data fields in the template populated with values.

    I just posted this in the community also.

    community.dynamics.com/.../894320

  • Suggested answer
    Euclides Pelisco Jr Profile Picture
    133 on at

    This post can help you accomplish this task.

    community.dynamics.com/.../894320

  • AshwiniShilpa Profile Picture
    30 on at

    Hello team,

    Could you please share custom workflow code to create email and associate template and use that in OOB workflow. This is needed urgently.

    Many Thanks

    Ashwini

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi AshwiniShilpa,

    Did you check the link shared above by Alex?

  • Ashwini Shashidhara Profile Picture
    27 on at

    Thanks Ravi for the response. Yes I did check that link, Alex link is about sending an email with template, I am looking for creating an email with template.

    Many Thanks

    Ashiwni

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at

    Hi Ashwini,

    Please refer below code for your reference:

    string emailTemplate = "Email template name here";

           FilterExpression filter = new FilterExpression();

           ConditionExpression conditionTitle = new ConditionExpression();

           ConditionExpression conditionType = new ConditionExpression();

           QueryExpression query = new QueryExpression();

           conditionTitle.AttributeName = "title";

           conditionTitle.Operator = ConditionOperator.Equal;

           conditionTitle.Values.Add(emailTemplate);

           conditionType.AttributeName = "templatetypecode";

           conditionType.Operator = ConditionOperator.Equal;

           conditionType.Values.Add("systemuser");

           filter.FilterOperator = LogicalOperator.And;

           filter.Conditions.Add(conditionTitle);

           filter.Conditions.Add(conditionType);

           query.Criteria = filter;

           query.ColumnSet = new ColumnSet();

           query.EntityName = "template";

           query.ColumnSet.Columns.Add("templateid");

           query.ColumnSet.Columns.Add("subject");

           query.ColumnSet.Columns.Add("title");

           EntityCollection templateCollection = service.RetrieveMultiple(query);

           tracingService.Trace("templateCollection retrived ... " + templateCollection.Entities.Count.ToString() + Environment.NewLine);

           Guid templateId = (templateCollection.Entities.Count > 0) ? (Guid)templateCollection[0].Id : Guid.Empty;

           Entity template = new Entity();

           InstantiateTemplateRequest request = new InstantiateTemplateRequest();

           request.RequestName = "InstantiateTemplate";

           request["TemplateId"] = templateId;

           request["ObjectId"] = userId;

           request["ObjectType"] = "systemuser";

           InstantiateTemplateResponse response = (InstantiateTemplateResponse)service.Execute(request);

           EntityCollection templateCollectionnew = (EntityCollection)response["EntityCollection"];

           tracingService.Trace("templateCollectionnew retrived ... " + templateCollectionnew.Entities.Count.ToString() + Environment.NewLine);

           Entity fromParty = new Entity("activityparty");

           fromParty["partyid"] = new EntityReference("systemuser", userId);

           EntityCollection collToParty = new EntityCollection();

           Entity User = service.Retrieve("systemuser", userId, new ColumnSet("internalemailaddress"));

           Entity toParty = new Entity("activityparty");

           string EmailAddress = User.Attributes.Contains("internalemailaddress") ? (string)User.Attributes["internalemailaddress"] : string.Empty;

           if (EmailAddress != string.Empty)

           {

               toParty["addressused"] = EmailAddress;

               toParty["partyid"] = new EntityReference("systemuser", User.Id);

               toPartyArray.Add(toParty);

           }

           collToParty.Entities.Add(toParty);

           Entity Email = new Entity("email");

           Email.Attributes["from"] = new Entity[] { fromParty };

           Email.Attributes.Add("to", collToParty);

           Email.Attributes["subject"] = subject;

           Email.Attributes["regardingobjectid"] = new EntityReference("incident", Complaint.Id);

           Email.Attributes["description"] = description;

           Email.Attributes["ownerid"] = new EntityReference("systemuser", userId);

           Guid NewEmail = service.Create(Email);

  • Ashwini Shashidhara Profile Picture
    27 on at

    Thanks Pravin. This helped.

    Thanks once gain for swift response

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans