Business Central Attach Email Body 📎📧

I recently did a post about how BC works with emails for CRM mostly. Check it out here: https://joshanglesea.wordpress.com/2022/07/01/business-central-crm-email-%f0%9f%93%a8/
This got me thinking about another scenario which I get asked about from time to time by prospective clients. If a customer/contact emails something important can you then attach that to a record in BC?

Now, I accept that attaching in BC is a nice user feature but I also appreciate long term it will build up the database size. I’m leaning towards the practical side of the argument in that checking emails in the interaction log entries isn’t that intuitive (check the referenced blog to understand more). Checking the attachments of a document or master record is though. Especially for critical information like a purchase order reference for a sales order. My idea for a solution stems from the wave 1 2022 release of this functionality – to save you checking it allows users to take email attachments into BC attachments for records: https://docs.microsoft.com/en-us/dynamics365-release-plan/2022wave1/smb/dynamics365-business-central/outlook-add-in-add-attachments-emails-directly-business-central-documents

If you have used the BC outlook add-in you will probably know about the “Suggested Line Items” feature. This is where you choose to create a new sales document and it reads the email body to find matches for items in the company. I’m mentioning this because the two features I’ve brought up resulted in my answer.
My scenario with an example. Here is an email exchange between Tim who is a BC user and his customer. They want to progress with the order and have responded with their Purchase Order reference with.
Using the BC Outlook add-in the user finds the Sales Order and follows the steps shown above – clicks on the ellipsis icon, scrolls and locates “Attachments”, finds a new button called “Attach email body”.
This will add the html of the email as an attachment record. I used the current date and time in conjunction with the email subject to create the name of the attachment. You could use something else of course.
Users aren’t able to view the attachments in the BC Outlook add-in – be it html or not. This is the message which pops up if they try.
However, in the BC web client a user can work with the attachment as normal by clicking on it to download, share or open in OneDrive. Given it is a HTML file I have added an extra option, which makes the most of a standard feature. The new button is “Preview Email” and it displays the HTML attachment. Granted it’s not perfect but it’s a quick and effective way of viewing the details without having to go rooting around in the interaction log entries
I’ve made it so the “enabled” property of the page action only works with files that have the html “File Extension”.

Like what you see? Want to try it out? You can find the code here: https://github.com/JAng13sea/Blogs/tree/master/Email%20Body

I attempted to make the HTML nicer by using https://www.hougaard.com/wysiwyg/ but the result was the same as the standard preview. If like me you want to have the preview formatted correctly you will need to try a different approach – which is another copy of how standard BC does it.

Here is how the preview page looks when it is passed the text value from a report object instead – which is then saved as HTML. Code for this one is on github too.

Business Central CRM Email 📨

During demo engagements I often get asked to demo BC CRM. This can be because it’s a good fit or a best of breed CRM is currently out of reach. As part of this they want to know how much can be done with emails – the bread and butter of CRM. There are a few different uses of the term “Email” in BC and how a user can send or review emails. I had to create a guide on each area so thought it might be worth a share. Given this is CRM focused it is worth noting that these features work with contacts*. I will cover the following email situations:

  • Outlook synchronisation (this is the main topic to cover)
    • From Outlook add-in
    • From within BC client
  • Create Interactions
  • Send By Email
  • Segments
  • Sending documents (*this works without contacts)

Outlook synchronisation

For details on how to setup this up check out this video: https://youtu.be/LXum6xzpRxE

Once the main setup has been done each user will be setup like so and will have a new folder added to Outlook called “Queue”. Jump to the bottom of the blog for new user setup tips

If contacts in BC is a new concept the easiest way to get up and running is using the BC Outlook add-in. Brand new contact from the lens of the BC Outlook add-in will ask to create a contact for the email address. This is the simplest way to get moving with contacts if you don’t have them in place already:

Creates a contact record – which is essentially a copy of the contacts you store in Outlook:

Respond to the email in Outlook as you would usually do. For the original email and the response entries are placed in the special “Queue” folder:

The “Queue” folder can be emptied if the above codeunit is running on the job queue.

Once the job queue has run it will bring in the emails to the interaction log entries:

*note the “Salesperson Code” depicts who the email is to/from. The “User ID” is in fact the user which originally setup the integration.

If a user chooses “Show Attachments”

It will display this message:

Which opens a new tab with the email from Outlook

If you reply in outlook, then the email will be available to view in the Interaction Log Entries – which you can open as shown before:

Detail is all available on the contact card:

What about if you use the “Send Email” feature in BC?

I’m choosing it from the Outlook add-in here but it is the same in the BC web client too

That also goes into the Outlook “queue” folder. The “Send Email” feature allows you to send as a different email address (the from address). If that isn’t a user synchronised with BC then the email will not go to the interaction log entries.

When done with the “current user” the email will appear in both the “Sent Items” and the “Queue” folders:

Once an email has been passed to BC the “Queue” folder will no longer contain the email. Because you have done this in BC you can also see the entries in another location, other than the Interaction Log Entries:

The Interaction Log Entries also has a copy just like before

The “Queue” is accessible by other users so you can see email traffic that has gone to BC defined contacts:

Different user accounts inbox view

What about seeing the BC details from Outlook? From the add-in you can access interaction log entries in a couple of places:

Drilldown on the

Create Interactions

“Create Interactions” is an action users see in scenarios where contacts are in use. It is available directly on the contact, opportunities, tasks or on the interaction log entries page. When using the feature you are effectively calling upon ready to go email or attachment templates.

Here is a basic free type email interaction to a contact
This pops open the BC email page before sending and adds it to the contact card in the “History” section:
The “Queue” folder will receive an entry too

What’s confusing about this is that you end up with two interaction log entries. One is the one instantly created by using the feature and the second is part of the Outlook synchronisation:

If the user clicks on the “Attachment” for the entry for Outlook it pops the message from earlier

If you choose the none Outlook one it opens a page like this:

How do you tell the difference? Use the “Email Logged” field as “TRUE” with a filter

Segments

The exception to this rule, if you use the “Segments” feature which uses interactions you do not get the duplication in the interaction log entries.

Here are some previously logged segments where specific contacts have been targeted. Can be for sales, marketing or customer service purposes.
When a user chooses an entry it will just show it in the preview page and not by opening Outlook

Sending Documents

The last email scenario a user can do is for documents. Posted Sales Invoice for example has 2 email related buttons but they both result in the same thing ultimately, however the 1st to the left asks an extra question about the output

Extra page which is shown when using the 1st “Send” email option

This will also create an interaction log entry:

And show it in your users “Sent Items”:

New User Setup

If a new user wants to have their emails synched then they we’ll need to firstly be setup in the user setup page and have a “Salespers./Purch. Code” assigned to them.

Following on from that the user will need to have their account synched. Access the above page from the early shown “Exchange Sync. Setup”. Add the “Queue” folder by choosing “Add Favourite” in Outlook. The “Queue” folder will be one of the options available to the user. If the new user doesn’t see any results in the Outlook “Queue” folder straight away don’t be surprised. Other users who have been connected for a while will see their activity though:
If you the user doesn’t get access to the folder then you can logon to exchange and force the issue by adding them to the public folder
New entries have the “JA” Salesperson Code

Business Central Service Management Email Queue 📨

The service management module of Business Central has an emailing feature which is designed to inform internal employees if service level agreements (SLA) are being missed. It also has a feature to update a customer on completion of a repair for a specific service item. The standard documentation on this area isn’t that great. Therefore I will explain in brief more about the feature and the required setups to make the most of it. At the time of writing this area is not part of the enhanced email capabilities and has little scope for configuration. An area I hope that improves in the future.

Part 1 is the Internal warning emails:

In the service management setup page you can determine the duration of time (in hours) that a series of warnings should fire off to internal staff members. In the “Send <> Warning To” fields just add the email address. It could be the same person each time or it could be a group email, the choice is yours.

Now that’s in place how is it being calculated that something has hit a “warning”? Over on a service contract we start to piece the puzzle together:

Each service item line can have a differing “Response Time (Hours)”. Note you can set this at header level too – in the “Service” fast tab. In my case the time to respond is seconds – like to set the bar high 😂 worth noting here that a service item must be part of a service contract for the SLA to count.

Once a service order is logged we have a date and time for that taking place – “Order Date”, “Order Time”.

This data coupled with the “Response Time (Hours)” value on the order, which just so happens to come from the service contract, gives us the expected SLA.

You can see the detail on the line level of the service order. Note it is the calculated value. In an earlier screenshot there is a field called “Warning Status” – this is where we can see what warning message has been sent. In my case it will jump straight to the third warning. Of course in a real life scenario it will step through as the clock ticks. Worth noting that the message will only ever happen once. So, if a user manually resets to the “Warning Status” but a message about it has already been sent then no new message will appear.

**Emails will only send if the Service Order has a status of Pending and the service order line has a “Repair Status Code” which is marked with “Initial” true** The out of the box setup here is something worth sticking to if you can but if you have your own repair status codes then I am referring to this setup:

In the case the service order line must be INITIAL for a warning email to send. Which effectively means, no one has started working on it yet. The interesting pat about this is when you have a multi line service order and you start work on it the overall “Status” of the order changes. Again I will state only “Pending” service orders get warnings. This is a good use case for the setup option “One Service Item Line/Order” – which would then give you greater control over getting warnings for all service items 👍

So, what do we need for the emails to start flying out? Two codeunits adding to the job queue entries page. Set them up to run as you need.

An example of the data in the service email queue:

Thing we can’t do is configure the “Subject Line” – would like that to change in future releases. If we need different detail then a customisation is needed here 😐 The table has a “Body Line” field which then produces the below email:

Part 2 – Customer notifications

A customer can be kept informed of the order with email messages when the codeunits from part 1 are in place. On the header of the service order there is a field called “Notify Customer” with a series of set options. Unfortunately, as standard the field is blank when the header is created. You would expect it to be linked to a customer record or even set at service order type, but no…..This means we have to set this manually per order, without customisation. You will also need the “Email” field to be populated, as standard it is blank too 👀 – you can see what I mean by having this area catch up with the enhanced email features:

To trigger an email to the chosen address you must mark the “Repair Status Code” to a value which sets the overall service order “Status” to Finished.

Upon doing that you will get this kind of message:

Unlike the warning messages this one will fire off multiple times if you chop and change the repair status code:

Final email looks like this. Again, with no current configuration options for changing what the email body is…

Some limitations in the standard offering but could be a nice thing to use if you have this module. The details mentioned are applicable to older versions of NAV which have the same module.

Business Central 2020 Wave 2 Enhanced Email Capabilities – How to setup

If you read over the latest changes shipped with version 17.1 you would have seen the enhanced email capabilities mentioned. This can be enabled early by checking out the feature management page:

Just doing this though doesn’t mean you can start to enjoy the new features straight away, there is some setup to handle. A lot of the required setup is described very well on the docs.microsoft.com site: https://docs.microsoft.com/en-us/dynamics365/business-central/admin-how-setup-email

However, that doesn’t always have all the steps in enough detail. The end goal of this functionality is to have dedicated email accounts for specific scenarios that need emailing from the system. Here is a configured list to illustrate where we want to end up:

All of the documents shown will now have the “From” address of accounts. This means a contact is more likely to reply directly to this group email rather than a direct contact 👍

Before getting started in Business Central go to the Office 365 admin centre and add shared email accounts for each of the scenarios that can be covered. Out of the box this includes documents based on sales, purchase, service and internal messages like approvals notifications (can be extended to cover more – save that for another time). These type of mailboxes therefore make sense:

The majority of the connection setup is done through a wizard where you either pick the current user account so you can send emails as your logged in BC user or choose one of the above shared mailboxes. The current user method is very simple so I will cover the shared mailbox

Search for “Set up Email” and cycle through the wizard page to the one shown (page 2), choose the shared mailboxes option. Note that if you’re not a user with the SUPER permission assigned you will need a new permission set called EMAIL SETUP which is available in the main list.
Add the details of one of the shared mailboxes from the Office 365 admin centre. Finish the wizard and test the connection. Repeat this step for the other accounts that you need.
Once you have added all the accounts if you search for “Email Accounts” you can see all of the available ones to work with. Note that the legacy SMTP connection will be created for you already and it will be the “default”. There is an action to reassign the default available from this page as well as testing the accounts or composing a none document related email with that account.
The next area of interest in this page is under the “Navigate” tab where you can see email activity with that account from BC and which “Email Scenarios” are assigned to the email account.
Simply choose the documents you want to be sent from that email account
From that point onwards your chosen account will be used for that document. Any previous email dialog screens have been replaced with this one. If you have email layouts setup they will work too.
On the role centre you will notice a new activity cue. The draft cues means that users are asked to save as a draft or to discard the email – much like a regular email experience.

I’ve configured this in two separate tenants thus far (as of 09/12/20) and the experience has been fairly slick. The only issue I experienced was to do with an Exchange configuration where no Office 365 connector was in place. If you are repeatedly given a message in BC about not being able to access the “Set up Email” page jump over to the Exchange admin centre and see the “Connectors” which currently lives under the “Mail Flow” area:

Users are able to search for “Compose an Email” to access the email editor with no document scenario assignment:

Would have been nice if the “Attach File” option let you search documents stored in BC but that is currently not the case. Right now that will let you choose a file from a locally accessible location.

A much richer experience overall. Look forward to seeing what others do to enhance this.

Business Central Batch post and e-mail with Power Automate – no code

Batch posting has been in the product for some time but I am not seeing a clear way, happy to be wrong, on batch post and e-mail. Here are my options (below) as a user conducting the posting. Yes, I have post via the job queue as well but from what I’ve tested this isn’t sending my e-mail for me. Even the print option breeds no results here. Thought it would at least use the “Document Sending Profile” on the customer record.

Even when you use the “Post Batch” you get nothing about e-mailing? 😬 Not forgetting the workflows in BC have no option for “Post & Send” it’s just “Post”. Usually these gaps would need filling with a code modification but not in this blog.

Where there is a will there is a way and my idea here is to use Power Automate to do the heavy lifting. On this occasion I will use a manual trigger but if this was a production ready scenario I would use a scheduled type flow.

The connector for BC in Power Automate is fairly small but I’m sure it will get better over time. There is a slight restriction though as the action of posting and emailing exists but it’s on a singular level like it is in the regular UI. So the first thing I need to do is fire in some data I can use in Power Automate from BC. I will of course need the GUID ID reference to the sales invoice as that’s what the BC Power Automate connector likes. The page that fits the bill here is available as a web service already. I will use the top one in the list 2811. This page is a mixture of open and posted sales invoices so some filtering is needed:

Example of the payload from this page:

Adding a filter to the ODATA query so I only post invoices that are ready to be posted. In the case of this page the “status” values are different to regular BC. In my case I have a choice between draft aka “Open” or open aka “Released”. So I have added ?$filter=status%20eq%20%27Draft%27%20and%20totalAmountIncludingTax%20gt%200 to the end of the web service URL I got from BC. Reason being the feature in the Power Automate BC connector restricts me to draft only and I don’t want to post invoices with a 0 value. Will log something on the Power Automate forum about the connector wanting “Open” invoices rather than “Released”. Backwards logic otherwise, what if I’m using approvals for instance. I think this is possibly wrong so I have posted this to find out more: https://powerusers.microsoft.com/t5/Connecting-To-Data/Is-the-Business-Central-Post-amp-Send-Invoice-action-correct/m-p/637081#M9492

Anyway….

Our flow starts to take shape like this. Check out my last blog for a more detailed account on the parse JSON part (https://joshanglesea.wordpress.com/2020/07/22/power-automate-purchase-order-alerts-to-vendor/)

Once we add the “id” from the parse JSON step you will get an “Apply to each” wrap around the chosen BC action which is exactly what we want (automatically). Remember our goal Batch post and e-mail invoices – so we better placed than standard.

In my case a small batch of invoices have been handled and emails dished out accordingly. I added an extra step for updating the posting date as well. Just so it takes something useful from the existing “Batch Posting” feature 👍

Business Central Power Automate purchase order alerts to vendor

Recently had a requirement where alerts to a vendor need sending for orders expected in the next two weeks. A reminder is needed as the lead times for the goods are so long.

The goal is therefore, have an email sent to a vendors email address for purchase order lines in the next two weeks from today’s date.

To achieve this Power Automate or Logic Apps are the most appropriate choices. For this blog I have chosen Power Automate.

Given that I will need line data and I want to minimise the need to make multiple HTTP calls so some small DEV BC side will help. I have produced a query object so that I have all the data I require for all the areas I want data from (link to my code is at the end). I’ve chosen header level here for the “Expected Receipt Date” but you could do it for the line level if needed:

Ensure the query is published as a web service and check you have output by using the web link or from an API test tool like Postman:

To get the exact data we want for the scenario some ODATA query logic is needed. Add the following to the end of the web service URL. Replace <Your Date> with the date you want to filter by. The format must be like this: 2020-07-21T00:00:00Z:

?$filter=Expected_Receipt_Date ge (<Your Date>) and Expected_Receipt_Date le (<Your Date>) and Outstanding_Quantity gt 0

The date values will be replaced with calculated fields in the flow which will be a scheduled type flow so that is our starting point along with the ability to create variables for the date/time values which are then used in our ODATA query above:

Use the HTTP connector and call the web service with a GET command and use the current time and future time variables.

The HTTP will produce JSON which we saw earlier, from the web service call, and to use the data from this we need to use the PARSE JSON feature and we’ll be able to then select the content for use in subsequent steps like sending the email. To generate the schema just paste in an example from calling the web service. Works nicely by using an API test tool like Postman as you get it formatted in a nicer structure.

Once the JSON is read by the PARSE JSON step you are able to create a “Apply to each” step which will iterate through each of the received rows of data until it has read them all. Whilst that is happening we can initiate further actions like our email:

Each reference comes from the PARSE JSON and you can use format functions on certain data like I have for the date. The result of this flow is an email much like this one:

Code: https://github.com/JAng13sea/Blogs/tree/master/Purchase_Query