I've been fighting trying to complete opening an email template instance with create form type for a bit. I found to be what a viable solution here: https://www.itaintboring.com/dynamics-crm/instantiating-an-email-template-with-web-api/
I've spent more than a full day trying various methods using remotecommand however it seems to be deprecated.
The following is my javascript:
function ltCreateIAafterPurchaseTemplate(executionContext, id){
alert("IA AFTER PURCHASE");
var formContext = executionContext;
var serialNo = formContext.getAttribute("new_licenseno").getValue();
var emailTemplateToLoad = "f22cb309-1fd9-eb11-bacb-000d3a361c51";
var licenseId = id;
licenseId = licenseId.toString().replace("{", "").replace("}", "");
var endUserContactId = formContext.getAttribute("new_endusercontactid").getValue()[0].id;
endUserContactId = endUserContactId.toString().replace("{", "").replace("}", "");
var parameters = {
"TemplateId": emailTemplateToLoad,
"ObjectType": "new_license",
"ObjectId": licenseId
};
var requestUrl = "/api/data/v9.2/InstantiateTemplate";
var req = new XMLHttpRequest();
req.open("POST", "">dev.api.crm.dynamics.com" + requestUrl, true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
alert(result.value[0].subject);
alert(result.value[0].description);
} else {
var errorText = this.responseText;
alert(errorText);
}
}
};
req.send(JSON.stringify(parameters));}
The above code executes and receive the following 401 response:
{"error":{"code":"","message":"No HTTP resource was found that matches the request URI '">dev.api.crm.dynamics.com/.../InstantiateTemplate'."}}
I could use a boost of help as I've been fighting with this all night. All ids in the param list are valid.
Regards.