Notifications
Announcements
No record found.
Hi there,I wonder if there is a way to get the e-mail template data via the REST call and setup the description to e-mail body.Please share your thoughts.Thanks
*This post is locked for comments
Hello,
Have you tried to do that using WebApi? Here are helpers that can make development of code much more easier for you - github.com/.../JS
I found and It works, code is below just pass the parameter Template guid and call "LoadTemplate" function on Email Load form :function LoadTemplate() { // Check the form type should be 'create' type
var emailTemplateToLoad = "358497C8-F902-E611-80F1-3863BB2E92C8"; //created email template Id
// Get Regarding object details var regardingobjectid = Xrm.Page.getAttribute("regardingobjectid"); if (regardingobjectid == undefined) { return; } var RegardingItems = Xrm.Page.getAttribute("regardingobjectid").getValue();
// The signature will not append if regarding field remains blank. if (RegardingItems != null) { var regardingObjectId = RegardingItems[0].id; var regardingObjectType = RegardingItems[0].type;
if (regardingObjectId == null || regardingObjectId == "") { return; } if (regardingObjectType == null || regardingObjectType == "") { return; }
// Retrieving email template details
var command = new RemoteCommand("EmailTemplateService", "GetInstantiatedEmailTemplate"); command.SetParameter("templateId", emailTemplateToLoad); command.SetParameter("objectId", regardingObjectId); command.SetParameter("objectTypeCode", regardingObjectType); var result = command.Execute();
if (result.Success) { var o = new Object(); o.EmailBody = ""; o.EmailSubject = ""; if (typeof (result.ReturnValue) == "string") { // Create a Xml Document of the return value to retrieve actual data oXml = CreateXmlDocument(result.ReturnValue); Xrm.Page.getAttribute("subject").setValue(oXml.lastChild.firstElementChild.textContent); Xrm.Page.getAttribute("description").setValue(oXml.lastChild.lastElementChild.textContent); } } }}
function CreateXmlDocument(signatureXmlStr) { // Function to create Xml formate of return email template data var parseXml; if (window.DOMParser) { parseXml = function (xmlStr) { return (new window.DOMParser()).parseFromString(xmlStr, "text/xml"); }; } else if (typeof window.ActiveXObject != "undefined" && new window.ActiveXObject("Microsoft.XMLDOM")) { parseXml = function (xmlStr) { var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.loadXML(xmlStr); return xmlDoc; }; } else { parseXml = function () { return null; } } var xml = parseXml(signatureXmlStr); if (xml) { return xml; }}
Hi,
We have tried the above-mentioned procedure to retrieve the email content. But we are facing issue while using oXml.lastChild.lastElementChild.textContent. We are able to retrieve the hard-coded content. But the dynamic data from entities is not getting populated. We have tried innerHTML / outerHTML, but they didn't work. Do we have to retrieve the data related to the entity separately and append it to email content? Or have you faced a similar issue and there is a workaround solution for this.
Thanks,
Sridhar.
I cant get this to work in D365 online. Keeps failing at var command = new RemoteCommand("EmailTemplateService", "GetInstantiatedEmailTemplate"); Did this change that you know of ?
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2