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=’’>&#8221; +
“<s:Body><Execute xmlns=’; xmlns:i=’’>&#8221; +
“<request i:type=’b:InstantiateTemplateRequest’ xmlns:a=’; xmlns:b=’’>&#8221; +
“<a:Parameters xmlns:c=’’>&#8221; +
“<a:KeyValuePairOfstringanyType>” +
“<c:key>TemplateId</c:key>” +
“<c:value i:type=’d:guid’ xmlns:d=’’>&#8221; + TemplateID + “</c:value>” +
“</a:KeyValuePairOfstringanyType>” +
“<a:KeyValuePairOfstringanyType>” +
” <c:key>ObjectType</c:key>” +
”          <c:value i:type=’d:string’ xmlns:d=’’>systemuser</c:value>&#8221; +
”       </a:KeyValuePairOfstringanyType>” +
”      <a:KeyValuePairOfstringanyType>” +
”       <c:key>ObjectId</c:key>” +
”      <c:value i:type=’d:guid’ xmlns:d=’’>&#8221; + FromUser + “</c:value>” +
”   </a:KeyValuePairOfstringanyType>” +
“</a:Parameters>” +
“<a:RequestId i:nil=’true’ />” +
“<a:RequestName>InstantiateTemplate</a:RequestName>” +
“</request>” +
“</Execute>” +
“</s:Body>” +

Enjoy !!

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


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: Logo

You are commenting using your 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