Html not recognized in email template while using custom macros
Hey,
I'm trying to implement business task when we need to send a datalist/table in email template.
I was surfing the academy and came into this https://community.creatio.com/questions/how-display-datalist-email-template
But i faced a little problem,
When inserting my macros to email template, the message itself not recognizing the html code.
Any suggestions how to fix it?
Thanks
Like
Oleksii Protsiuk,
Hello,
&lt; means that there should've been < in the code. I believe there is an issue with the html code translation in your template. You need to replace:
&lt; with <
&gt; with >
&gt with > either
using Notepad++ replacement for example (I've modified the code you sent using this text editor). As a result I received a correct code, but after that the HTML should be checked. This can be done via the tests in Visual Studio and receivig the HTML code result and verifying it for example here. You can use some test values instead of entity.GetColumnValue(colPercentage.Name).ToString() to verify the code.
Dear Oleksii,
Thanks for reaching out.
Could you please provide us an example of macros you are trying to insert into your email template?
Thanks in advance.
Best regards,
Anastasiia
Anastasiia Marushenko,
namespace Terrasoft.Configuration { using System; using Terrasoft; using Terrasoft.Common; using Terrasoft.Core; using Terrasoft.Core.Entities; using Terrasoft.Core.DB; using Newtonsoft.Json; public class NewEmailMacros : IMacrosInvokable { public UserConnection UserConnection { get; set; } public string GetMacrosValue(object arguments) { // var sjson = JsonConvert.SerializeObject(arguments); // var templ = new {Key = String.Empty, Value = String.Empty}; var currencyId = "c1057119-53e6-df11-971b-001d60e938c6"; var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, “Object"); var colCode = esq.AddColumn("Column1"); var colPercentage = esq.AddColumn("Column2"); var colCurrency = esq.AddColumn("Column3"); var colType = esq.AddColumn("Column4"); var colDate = esq.AddColumn("Column5"); var colDay = esq.AddColumn("Column6"); var CurrencyFilter = esq.CreateFilterWithParameters( FilterComparisonType.Equal, "Column3.Id", currencyId); esq.Filters.Add(CurrencyFilter); EntityCollection entities = esq.GetEntityCollection(UserConnection); var html = "&lt;table&gt;&lt;tr&gt;&lt;td&gt;Percentage&lt;/td&gt;&lt;td&gt;&lt;th&gt;Code&lt;/th&gt;&lt;/td&gt;&lt;td&gt;Currency&lt;/td&gt;&lt;td&gt;Type&lt;/td&gt;&lt;td&gt;Date&lt;/td&gt;&lt;td&gt;Day&lt;/td&gt;&lt;/tr&gt"; foreach (Entity entity in entities) { html += "&lt;tr&gt;"; html += "&lt;td&gt;" + entity.GetColumnValue(colPercentage.Name).ToString() + "&lt;/td&gt;"; html += "&lt;td&gt;" + entity.GetColumnValue(colCode.Name).ToString() + "&lt;/td&gt;"; html += "&lt;td&gt;" + entity.GetColumnValue(colCurrency.Name).ToString() + "&lt;/td&gt;"; html += "&lt;td&gt;" + entity.GetColumnValue(colType.Name).ToString() + "&lt;/td&gt;"; html += "&lt;td&gt;" + entity.GetColumnValue(colDate.Name).ToString() + "&lt;/td&gt;"; html += "&lt;td&gt;" + entity.GetColumnValue(colDay.Name).ToString() + "&lt;/td&gt;"; html += "&lt;/tr&gt;"; } html += "&lt;/table&gt;"; return html; } } }
Anastasiia Marushenko,
I dont know why it kept changing the code, and adding the amp*
html += "</table>";
Oleksii Protsiuk,
Hello,
&lt; means that there should've been < in the code. I believe there is an issue with the html code translation in your template. You need to replace:
&lt; with <
&gt; with >
&gt with > either
using Notepad++ replacement for example (I've modified the code you sent using this text editor). As a result I received a correct code, but after that the HTML should be checked. This can be done via the tests in Visual Studio and receivig the HTML code result and verifying it for example here. You can use some test values instead of entity.GetColumnValue(colPercentage.Name).ToString() to verify the code.
You can use the Enhanced template macros for Creatio app from Marketplace.
You won't need to write additional code.
https://marketplace.creatio.com/app/enhanced-template-macros-creatio