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)

Button to open email with template already inserted

(0) ShareShare
ReportReport
Posted on by 2

Hi,

In certain circumstance we need ta open an email with the message already filled so that the user doesn't have to go through the 'insert template' wizard.

Is this possible to do by javascript or another way?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    You can use the openEntityForm function of the Xrm.Utility library.

    The Xrm.Utility provides you the ability to pass parameters to the entity when it is opened.

    See example below on msdn.

    msdn.microsoft.com/.../jj602956.aspx

    msdn.microsoft.com/.../gg334375.aspx

    parameters["templateid"] = "2878282E-94D6-E111-9B1D-00155D9D700B"; // Guid of Email Template

    parameters["templateidname"] = "Name of Email Template";

    parameters["templateidtype"] = "template";

    Please confirm names of fields above...

  • Suggested answer
    Goutham A Profile Picture
    2 on at

    Yes, you can do it as suggested by Aric.

    Also, without using template at all, you can populate the text also directly if required

    var Parameters={};
    Parameters["subject"]="subject";
    Parameters["description"]= // your body text goes here
    var windowOptions = { openInNewWindow: true};
    Xrm.Utility.openEntityForm('email',null,parameters,windowOptions);
    please refer below links
    https://community.dynamics.com/crm/f/117/t/169962  -- (THIS ADDRESSES SIMILAR ISSUE)
  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    Hi,

     I think you'll need to use InstantiateTemplateRequest:

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

    msdn.microsoft.com/.../mt592993.aspx

     So you would likely have to create a javascript that will execute that request, get email id from the response, and, then, use OpenEntityForm to open that email..

     MSDN has a number of java scripts for Web API:

    msdn.microsoft.com/.../mt770365.aspx

     The reason it may not work with the parameters is that (I think) when creating an email from a template, that email has to be saved first (otherwise, if a template has attachments, for example, there is nothing to attach those files to until the email is saved). That's what InstantiateTemplateRequest is supposed to take care of, though.

  • Birgit RD Profile Picture
    2 on at

    With the combination of all information I got, I'll be able to build what is needed for the project

  • Brandon Duncan Profile Picture
    20 on at

    The accepted answer worked great for me. However in order to get the email body (description) to populate from the template on page load, I had to pass an empty string (with a space) as the description parameter. Here is my final solution:

           //Set template lookup parameter to pass to email

           var template = {

               id: {email template id},

               name: {email template name},

               entityType: "template"

           };

           //Set regardingobjectid lookup

           var regardingLookup = {

               id: formContext.data.entity.getId().replace(/[{}]/g, ''),

               name: formContext.data.entity.getPrimaryAttributeValue(),

               entityType: "incident"

           };

           var parameters = {

               formId: emailFormId,

               regardingobjectid: regardingLookup,

               templateid: template,

               description: " " // Here is where I had to add an empty description (must have space character)

           };

           var entityFormOptions = {};

           entityFormOptions["entityName"] = "email";

           Xrm.Navigation.openForm(entityFormOptions, parameters);

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