Adding Table to the Email Template in Dynamics CRM 365

User Review
0 (0 votes)

Ever wondered why Sales is one of the pivotal departments in an organization? It’s not easy to meet a stranger, talk about your service or product within a short span of time and convince him/her to reach into the pocket and shell out some money.

The unique and important role of Sales is to bridge the gap between the potential customer’s needs and the products/services that the organization offers that can fulfill their requirements. And every organization has its own way of doing sales including approaching customers, making deals, selling products/services and involving a unique sales pipeline.


Now in such a high pulsating environment, you can’t expect a Sales rep to shuffle between several systems to get the information on one client. This can lead to an immense wastage of time and resources and maybe the loss of a potential client.

With Dynamics 365, the whole story gets a fresh spin. Your sales rep can find all the answers in one system. The time that was spent moving from one application to the other, can now be utilized to pitch the product/service to another client. Thus, eventually increasing your ROI.

Even though Dynamics 365 is one of the most trustworthy and scalable CRMs around, it isn’t devoid of certain challenges. We are aware of the role that emails play in our professional lives.  For Sales, using it in CRM, is like a lifeline as so many functionalities are attached to it. Such as connecting with the customer, sending out quotes, discussing deadlines, creating approval requests and so on.

This widely used communication feature needs to be a hassle-free affair for any professional. However, there are certain limitations to it as well in the Dynamics CRM. Let’s discuss.


Adding tables or HTML contents with out of box features and a little bit of custom code instead of designing completely new email templates.


In general, a company’s sales depend on so many factors but in my opinion, the sales representative is the primary aspect. There is a lot a sales representative can do- reaching out to leads/prospects, explaining the products, providing quotes, making offers, providing discounts. And finally selling the product/service. In such cases, there will be a lot of emails that keep on ricocheting between the rep and the client.

Customers look for products at affordable prices and mostly try to enquire with other competitors for different features and one of the main aspects is the cost. Everyone wants the best but at an affordable price range. So, most of the organizations give permissions to the sales representative to apply discounts to match with the competition.


When an organization gives permission to a sales representative for applying discounts on quotes, the business may have an approval process in place to ensure that the discount is limited based on the positions. A sales representative will create a quote, request for an approval decision (if it crosses the sales rep max discount limit) which needs a green signal from the manager/Director of Sales/Vice President of Sales. This is a hectic process wherein the rep must go through each record for their approvals.

An approver might want to see who the customer is, what are the products that have been requested for the discount and the discount rate. Now if all this information gets added, it will certainly increase the size of the email.

In order to make it shorter, a table format for all the data can be used and the data will appear in an organized manner. However, adding tables to an email message description is not an in-built feature. In this scenario, the table needs to be dynamic as well (needs to contain rows as per the number of quote details or products).


Generally, we use workflows to send automated email messages where we can send an email or create one and send it in later. For adding a table to the email description, we use Create Email Message and the email message will be created with the details intended to keep.

A replacing string in the email description needs to be added where the table is placed. This replacing string later is used in custom workflow plugin step to insert table.

It’s important to have a custom workflow, which will execute with the context of the created email message.



public InArgument<EntityReference> Email { get; set; }

protected override void Execute(CodeActivityContext executionContext)


IOrganizationService _service = servicefactory.CreateOrganizationService(context.UserId);

var tableData = ProductCategoryTable.Get<string>(executionContext);

if (!string.IsNullOrEmpty(tableData))


Entity email = _service.Retrieve(“email”,

Email.Get<EntityReference>(executionContext).Id,new ColumnSet(“description”));

tableData = GetTable(_service, QuoteGuid);

email.Attributes[Constants.Email.Description] =

email.Attributes[“description”].ToString().Replace(“[replacingString]”, tableData);



_service.Execute(new SendEmailRequest()


EmailId = Email.Get<EntityReference>(executionContext).Id,

IssueSend = true,

TrackingToken = string.Empty



private string GetProductCategoryDiscountTable(IOrganizationService _service, string quoteGuid)


var tablestring = string.Empty;

var GetProductCategoryRollups = @”<fetch version=’1.0′ output-format=’xml-platform’

mapping=’logical’ distinct=’false’>

<entity name=’quoteDetails’>

<attribute name = ‘product_id’ />

<attribute name = ‘amount’ />

<attribute name = ‘discountAmount’ />

<attribute name = ‘discountPercentage’ />

<filter type = ‘and’ >

<condition attribute=’quote_id’ operator=’eq’ value='{0}’ />




var productDetails =

_service.RetrieveMultiple(new FetchExpression(string.Format(GetProductCategoryRollups, quoteGuid))).Entities.ToList();

if(productCategoryRollups.Count > 0)


foreach(var product in productDetails)


tablestring = “<tr>” + “<td>” +

product.GetAttributeValue<EntityReference>(“product_id”).Name + “</td>” + “<td>”+

Decimal.Round(product.GetAttributeValue<Money>(“amount”).Value, 2) + “</td>” +

“<td>” + Decimal.Round(product.GetAttributeValue<Money>(“discountAmount”).Value, 2)

+ “</td>” + “<td>” + product.GetAttributeValue<Decimal>(“discountPercentage”) + “%”

+ “</td>” + “</tr>” + tablestring;



if (tablestring!= string.Empty)


//This is to add colum headers

tablestring = “<table>” + <tr> + “<th>” + “NAME” + “</th>” + “<th>” + “AMOUNT” +

“</th>” + “<th>” + “DISCOUNT” + “</th>” + “<th>” + “DISCOUNT PERCENTAGE” + “</th>” +

“</tr>” + tablestring + “</table>”


return tablestring;


Our certified consultants can help bridge the gap by classifying main requirements, developing CRM roadmaps, and restructuring lead-to-cash implementations. Connect with us for changing the way your business operates.

Download our 15 Questions to Identify the Gaps in Your CRM

The post Adding Table to the Email Template in Dynamics CRM 365 appeared first on CRM Software Blog | Dynamics 365.