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 0

Like

6 comments
Best reply

Oleksii Protsiuk,

 

Hello,

 

&amp;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:

 

&amp;lt; with <

&amp;gt; with >

&amp;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 = "&amp;lt;table&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Percentage&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;th&amp;gt;Code&amp;lt;/th&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Currency&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Type&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Date&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Day&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt";
            foreach (Entity entity in entities) {
 	          	html += "&amp;lt;tr&amp;gt;";
 	          	html += "&amp;lt;td&amp;gt;" + entity.GetColumnValue(colPercentage.Name).ToString() + "&amp;lt;/td&amp;gt;";
            	html += "&amp;lt;td&amp;gt;" + entity.GetColumnValue(colCode.Name).ToString() + "&amp;lt;/td&amp;gt;";
     	      	html += "&amp;lt;td&amp;gt;" + entity.GetColumnValue(colCurrency.Name).ToString() + "&amp;lt;/td&amp;gt;";
      	     	html += "&amp;lt;td&amp;gt;" + entity.GetColumnValue(colType.Name).ToString() + "&amp;lt;/td&amp;gt;";
         	  	html += "&amp;lt;td&amp;gt;" + entity.GetColumnValue(colDate.Name).ToString() + "&amp;lt;/td&amp;gt;";
				html += "&amp;lt;td&amp;gt;" + entity.GetColumnValue(colDay.Name).ToString() + "&amp;lt;/td&amp;gt;";
            	html += "&amp;lt;/tr&amp;gt;";
            }
				html += "&amp;lt;/table&amp;gt;";
            	return html;
        }
    }
}

 

Anastasiia Marushenko,

I dont know why it kept changing the code, and adding the amp*

html += "&lt;/table&gt;";

 

 

Oleksii Protsiuk,

 

Hello,

 

&amp;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:

 

&amp;lt; with <

&amp;gt; with >

&amp;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.

Oleg Drobina,

Thank you very much!

That helped.

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

Show all comments