InstantiateTemplateRequest using Javascript – MS CRM 2011


If you want to create new email using template or want to place email template contents to email while replying, you need to use”InstantiateTemplateRequest” to initiate email template. It has three below parameters

TemplateId (ID of the email template that you want to use)

ObjectId (associated entity record id, (for example you have used data field from user entity then this will be the system user id)

ObjectType (data field’s associated entity name)

In my example, I have used system user entity’s data fields in my template, so here is the code to Initiate email template using Soap request.

function InstatiateEmailTemplate(TemplateID, FromUser) {
var Soapreq = “<s:Envelope xmlns:s=’http://schemas.xmlsoap.org/soap/envelope/’>&#8221; +
“<s:Body><Execute xmlns=’http://schemas.microsoft.com/xrm/2011/Contracts/Services&#8217; xmlns:i=’http://www.w3.org/2001/XMLSchema-instance’>&#8221; +
“<request i:type=’b:InstantiateTemplateRequest’ xmlns:a=’http://schemas.microsoft.com/xrm/2011/Contracts&#8217; xmlns:b=’http://schemas.microsoft.com/crm/2011/Contracts’>&#8221; +
“<a:Parameters xmlns:c=’http://schemas.datacontract.org/2004/07/System.Collections.Generic’>&#8221; +
“<a:KeyValuePairOfstringanyType>” +
“<c:key>TemplateId</c:key>” +
“<c:value i:type=’d:guid’ xmlns:d=’http://schemas.microsoft.com/2003/10/Serialization/’>&#8221; + TemplateID + “</c:value>” +
“</a:KeyValuePairOfstringanyType>” +
“<a:KeyValuePairOfstringanyType>” +
” <c:key>ObjectType</c:key>” +
”          <c:value i:type=’d:string’ xmlns:d=’http://www.w3.org/2001/XMLSchema’>systemuser</c:value>&#8221; +
”       </a:KeyValuePairOfstringanyType>” +
”      <a:KeyValuePairOfstringanyType>” +
”       <c:key>ObjectId</c:key>” +
”      <c:value i:type=’d:guid’ xmlns:d=’http://schemas.microsoft.com/2003/10/Serialization/’>&#8221; + FromUser + “</c:value>” +
”   </a:KeyValuePairOfstringanyType>” +
“</a:Parameters>” +
“<a:RequestId i:nil=’true’ />” +
“<a:RequestName>InstantiateTemplate</a:RequestName>” +
“</request>” +
“</Execute>” +
“</s:Body>” +
“</s:Envelope>”;
}

Enjoy !!

Note: if you are copying this code, please make sure to change quotes.

Advertisements

4 Comments

Filed under MS CRM 2011

4 responses to “InstantiateTemplateRequest using Javascript – MS CRM 2011

  1. Steven Rasmussen

    Thanks for posting this!!! I was just trying to figure out how to do this. Thanks again!

  2. ashish

    Nice one..

  3. Albi

    Hey, I have to do something like this just for service-cases. In my case I have to write an email using a email template to a customer. I want, that if I press a button the fields are automatically filled with a email template which is associated with this button…

    Could you tell me how to do this?

    • HIMBAP

      You can use a direct email option and select you template for creating email it will automatically have template fields populated automatically. or can have custom ribbon button to use above request. contact us if you need help to implement this requirement.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s