Create custom notifications on email opens
You have probably all seen the notifications in Dynamics 365 when a customer or prospect opens an email message. This notification shows in the timeline on the bottom of an email message, but if you don’t check it, you won’t see it! Another place where these notifications can become visible is in the Dynamics 365 assistant…if you set up a notification for this when you created the email in Dynamics 365, but again this is something that you will need to check every once in a while. What if there was a way to use the tools from Dynamics 365 and the Power Platform to send an in-app notification when an email is opened?
In this article I am going to show you how you can do exactly that! I’ve written an article on how to create in-app notifications in the past, but for this article I will use the In-App Notification builder that is part of the XRM Toolbox created by Ivan Fricko. I really wanted to hightlight this tool as it makes it SUPEREASY for system administrators to create these types of notifications, without needing to know any scripting or json type of code! Below is an example of what these types of notifications (can) look like, and this is exactly what I am going to explain how to build in this article!
Create a Power Automate Flow
The first thing I am going to do is create a power automate flow that will trigger when an email message has been opened. You will be surprised how simple and easy this is going to be! To create the Power Automate flow you’ll need to open the Power Automate Page and log in. Make sure you are working in the correct environment! (You wouldn’t believe how often I forget to check and end up working in the wrong environment!) From the main screen, navigate to the solution you want to add the flow to. Click on the ‘New’ button and select ‘Automation’ and ‘Cloud flow’ > ‘Automated’. When the window loads you can click on the ‘Skip’ button on the bottom of the screen to load the Power Automate configuration screen. Once the page loads, you’ll need to search for the ‘When a row is added, modified or deleted’ trigger for dataverse. The change type needs to be set to ‘Modified’ and the table name is ‘Email messages’. In my example I want this to have a scope of organization. Since I only want this flow to run when the email is opened, I am going to enter the following in the ‘Filter rows’ field of the flow: (opencount gt 0) This means that the value in the ‘opencount’ field in the email messages table needs to be larger than 0. In this example I will get an email notification each time someone opens the email, even if this is multiple times, so you might want to change this to (opencount eq 1) so users only get the notification on the first open.
Creating the notification
Let’s open the n-App Notification Builder in the XRM Toolbox and start building out the notification! After we create the notification we can copy and paste the code into the Power Automate flow. Once you open the tool, you’ll notice some of the same fields in the application. Enter the title of the notification in the ‘Title’ field. I entered ‘Your email was opened!’ in the title field. You’ll notice a preview shows on the right side of the screen. The title is shown in bold on top of the notification. In the body of the email you can enter more details, including dynamic content from the email! In this example I entered: ‘Your email SUBJECT has been opened! The SUBJECT part of this message is where I will need to enter dynamic content from the email record in dynamics 365. This is just a placeholder so I know I need to replace it with dynamic content in the Power Automate flow. Below the Body field you’ll notice the Toast Type and (if this is set to timed, which in my case it is) below the Toast Type you can set the expiration time of the notification. This is important because notifications are records in Dynamics 365, so you want to make sure they get cleaned up and not just sit in the database forever. In this case I’ll set the expiration date to 1 day. Below the ‘Expires in’ field you’ll notice the icon field. You can choose any of the existing icons, or you can pick ‘custom’ and select a different icon from Dynamics 365. If you have uploaded custom icons, this is also where you’ll be able to find them. For this example I am using a custom icon that is already part of my Dynamics 365 instance called ‘Email Icon’. (How fitting!)
Lastly you’ll notice the actions window on the bottom of the screen. This is where I am going to configure an action that will allow users to click on a link to open the email message the notification is referring to. Click on ‘+Add’ to and enter ‘Open Email’ in the text field. Set the ‘Open As’ to ‘New Window’ and set the ‘Type’ field to URL. I also entered http://bing.com in the url field to remind myself that this needs to be replaced with dynamic content (which will be the dynamics link to the actual email) in the Power Automate flow later. At this point in time you can click on the ‘Test’ icon to see what this would look like in Dynamics 365. Now that the notification has been built, I need to get the ‘code’ for my power automate flow. You can do this by clicking on the black ‘Get Code’ button on the top of the screen. You’ll see 3 options, make sure you pick the Power Automate option. In this point in time we’re ready to use this code in Power Automate, so make sure you go back to the Power Automate flow we were working on and open the details of the ‘Add a new row’ step we added previously. Copy the data in the ‘Title’ field (from the notification builder) into the ‘Title’ field in the Power Automate flow. We are going to do the same for the ‘Body’ field. Once you pasted the content in the ‘Body’ field, highlight the word ‘SUBJECT’ and replace it with the subject field in the dynamic content window. I would recommend using quotes before and after the subject, so that folks know this is the title of the email message the notification is related to.
Copy and paste the data in the ‘Data’ field in the Power Automate flow. You want to make sure you replace the Bing URL with your org’s URL. In my case I want to open the email message in the Sales Hub, so I need to get part of that URL into my Power Automate flow. The easiest way to do this is to open an existing email message and copy the entire URL except for the email ID, which is the last part of the link. It will look something like this: https://YOURORG.crm.dynamics.com/main.aspx?appid=5e37f33f-515b-e811-a854-000d3a11470e&newWindow=true&pagetype=entityrecord&etn=email&id=
NOTE: Make sure you replace YOURORG with your organization.
I didn’t copy the email ID part of the URL, as I am going to add this in the Power Automate flow as dynamic content. (The email ID is the unique identifier or GUID of the record, it shows as ‘Email Message’ in the dynamic content window.) After you’ve completed this, please make sure you copy the values for the ‘Expiry’ field, and set the ‘Icon type’ field. If you want to show the notification to the email owner only, then you also need to populate the ‘Owners(owners)’ field, by entering systemusers and the dynamics owner value in parentheses. The image above shows what it looks like in the Power Automate flow. Now all you have to do is test it and you’re good to go! I hope you found this article informative! Be sure to check in again next week for a new article or subscribe here to never miss another post!
Comments are Closed