{"id":803,"date":"2012-09-01T07:29:32","date_gmt":"2012-09-01T07:29:32","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=803"},"modified":"2012-09-01T07:29:32","modified_gmt":"2012-09-01T07:29:32","slug":"instantiatetemplaterequest-using-javascript-ms-crm-2011","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=803","title":{"rendered":"InstantiateTemplateRequest using Javascript &#8211; MS CRM 2011"},"content":{"rendered":"<p>If you want to create new email using template or want to place email template contents to email while replying, you need to use&#8221;InstantiateTemplateRequest&#8221; to initiate email template. It has three below parameters<\/p>\n<p><strong>TemplateId<\/strong> (ID of the email template that you want to use)<\/p>\n<p><strong> ObjectId<\/strong> (associated entity record id, (for example you have used data field from user entity then this will be the system user id)<\/p>\n<p><strong>ObjectType<\/strong> (data field&#8217;s associated entity name)<\/p>\n<p>In my example, I have used system user entity&#8217;s data fields in my template, so here is the code to Initiate email template using Soap request.<\/p>\n<p>function InstatiateEmailTemplate(TemplateID, FromUser) {<br \/>\nvar Soapreq = &#8220;&lt;s:Envelope xmlns:s=&#8217;http:\/\/schemas.xmlsoap.org\/soap\/envelope\/&#8217;&gt;&#8221; +<br \/>\n&#8220;&lt;s:Body&gt;&lt;Execute xmlns=&#8217;http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts\/Services&#8217; xmlns:i=&#8217;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8217;&gt;&#8221; +<br \/>\n&#8220;&lt;request i:type=&#8217;b:InstantiateTemplateRequest&#8217; xmlns:a=&#8217;http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts&#8217; xmlns:b=&#8217;http:\/\/schemas.microsoft.com\/crm\/2011\/Contracts&#8217;&gt;&#8221; +<br \/>\n&#8220;&lt;a:Parameters xmlns:c=&#8217;http:\/\/schemas.datacontract.org\/2004\/07\/System.Collections.Generic&#8217;&gt;&#8221; +<br \/>\n&#8220;&lt;a:KeyValuePairOfstringanyType&gt;&#8221; +<br \/>\n&#8220;&lt;c:key&gt;TemplateId&lt;\/c:key&gt;&#8221; +<br \/>\n&#8220;&lt;c:value i:type=&#8217;d:guid&#8217; xmlns:d=&#8217;http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/&#8217;&gt;&#8221; + TemplateID + &#8220;&lt;\/c:value&gt;&#8221; +<br \/>\n&#8220;&lt;\/a:KeyValuePairOfstringanyType&gt;&#8221; +<br \/>\n&#8220;&lt;a:KeyValuePairOfstringanyType&gt;&#8221; +<br \/>\n&#8221; &lt;c:key&gt;ObjectType&lt;\/c:key&gt;&#8221; +<br \/>\n&#8221;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;c:value i:type=&#8217;d:string&#8217; xmlns:d=&#8217;http:\/\/www.w3.org\/2001\/XMLSchema&#8217;&gt;systemuser&lt;\/c:value&gt;&#8221; +<br \/>\n&#8221;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/a:KeyValuePairOfstringanyType&gt;&#8221; +<br \/>\n&#8221;\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;a:KeyValuePairOfstringanyType&gt;&#8221; +<br \/>\n&#8221;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;c:key&gt;ObjectId&lt;\/c:key&gt;&#8221; +<br \/>\n&#8221;\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;c:value i:type=&#8217;d:guid&#8217; xmlns:d=&#8217;http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/&#8217;&gt;&#8221; + FromUser + &#8220;&lt;\/c:value&gt;&#8221; +<br \/>\n&#8221;\u00a0\u00a0 &lt;\/a:KeyValuePairOfstringanyType&gt;&#8221; +<br \/>\n&#8220;&lt;\/a:Parameters&gt;&#8221; +<br \/>\n&#8220;&lt;a:RequestId i:nil=&#8217;true&#8217; \/&gt;&#8221; +<br \/>\n&#8220;&lt;a:RequestName&gt;InstantiateTemplate&lt;\/a:RequestName&gt;&#8221; +<br \/>\n&#8220;&lt;\/request&gt;&#8221; +<br \/>\n&#8220;&lt;\/Execute&gt;&#8221; +<br \/>\n&#8220;&lt;\/s:Body&gt;&#8221; +<br \/>\n&#8220;&lt;\/s:Envelope&gt;&#8221;;<br \/>\n}<\/p>\n<p>Enjoy !!<\/p>\n<p>Note: if you are copying this code, please make sure to change quotes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to create new email using template or want to place email template contents to email while replying, you need to use&#8221;InstantiateTemplateRequest&#8221; 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&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=803\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[73,91,92],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/803"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=803"}],"version-history":[{"count":0,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/803\/revisions"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}