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=’’>” +
“<s:Body><Execute xmlns=’’ xmlns:i=’’>” +
“<request i:type=’b:InstantiateTemplateRequest’ xmlns:a=’’ xmlns:b=’’>” +
“<a:Parameters xmlns:c=’’>” +
“<a:KeyValuePairOfstringanyType>” +
“<c:key>TemplateId</c:key>” +
“<c:value i:type=’d:guid’ xmlns:d=’’>” + TemplateID + “</c:value>” +
“</a:KeyValuePairOfstringanyType>” +
“<a:KeyValuePairOfstringanyType>” +
” <c:key>ObjectType</c:key>” +
”          <c:value i:type=’d:string’ xmlns:d=’’>systemuser</c:value>” +
”       </a:KeyValuePairOfstringanyType>” +
”      <a:KeyValuePairOfstringanyType>” +
”       <c:key>ObjectId</c:key>” +
”      <c:value i:type=’d:guid’ xmlns:d=’’>” + 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.

5 thoughts on “InstantiateTemplateRequest using Javascript – MS CRM 2011

  1. 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?

    1. HIMBAP Post author

      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