Wednesday, 10 June 2020

PDF Automation series - Part 2: How to create a custom connector for Dynamics 365

In Part 1: How to create a Word template in Dynamics 365 of my PDF automation series I covered how to create a Word Template in Dynamics 365 as a Document Template record is referenced in the API request that will generate the PDF based on the entity defined in the Word Template.

In this episode, Part 2 will cover how to create a custom connector for Dynamics 365 in Power Automate. In the custom connector two actions will be created where there will be 
  1. An action that calls the ExportPdfDocument Dynamics 365 API request - this will generate a PDF based on a Document Template record that has a defined Word Template
  2. An action that calls the activitymimeattachments Dynamics 365 API request - this will attach the PDF file generated from the previous action to an email activity record
Prior to creating a custom connector, a prerequisite task is to create an App Registration in Azure Portal which I will cover.

**I'd like to make it clear that as of today, Convert to PDF is configured and supported in the Dynamics 365 Sales Hub app**

Use Case

Before we jump into the How To's, a reminder that the use case for this series will be

As a customer,

I want to receive a Tax Receipt of my purchase in an email,

so that I have confirmation of my purchase.

The life cycle of the process will be
  1. A Dynamics 365 Invoice record is updated to paid.
  2. My flow in Power Automate is triggered that handles all the magic.
  3. The customer associated to the Invoice will receive an email with a PDF attached that represents their Tax Receipt.

Why is a custom connector needed?

This PDF Automation series stemmed from my curiosity of whether we can automate the Convert to PDF functionality. As mentioned in my vlog, as of today the Convert to PDF is what we refer to as "on-demand" where it requires an end user to select a Document Template before creating or emailing the converted Word Template associated to the Document Template record as a PDF. 

Stefan Strube another Microsoft MVP in our community published this blog post where he shared how to automatically generate a PDF which is fundamental to my PDF Automation series. Thanks Stefan and hello! 😄 The action used in Stefan's blog post is the Invoke an HTTPs request which works.

If there is a use case for an end user to trigger the automation on selection of a record the following experience will appear where they are prompted to provide the configuration information for the Invoke an HTTPs request action. Chances are the end user may not know this information and it's not a smooth end user experience. The workaround is to use a custom connector that has the authentication configured to prevent the end user from having to enter in details regarding the Dynamics 365 instance for the Sales Hub app.

How to create an App Registration in Azure Portal for your Dynamics 365 instance

An App Registration is required to allow the custom connector to use Azure AD as a way of authentication to the Dynamics 365 instance. Whenever connectors are used in flows within Power Automate, a connection using credentials to the service is needed. For example when using a SharePoint action you have the ability to select a connection. Same concept applies to a custom connector. A couple of material you can read,
  1. This docs.microsoft.com article clearly explains the steps required to create an App Registration in Azure portal.
  2. This docs.microsoft.com article provides some further explanation on what is an App Registration.
The following are the steps that I showed in my WTF vlog.

Log into Azure portal and search for App Registration.


Click on +New Registration.


Enter a Name and select whether you want a single tenant or multiple tenant followed by the register button. We'll come back to the Redirect URI configuration after the customer connector has been created.


There will be a message that indicates the App Registration is being created.


Once created you'll see details of the App Registration which will be referenced when the custom connector for Dynamics 365 is created.


A couple of things need to be configured afterwards. The first one I showed in my vlog was to enable API permissions for Dynamics 365. The custom connector will access with the Dynamics 365 API using the connection configured for the selected custom action (this will make sense in Part 3 of my PDF Automation series). Head over to API permissions and click on +Add a permission and select the Dynamics CRM option.


Tick the checkbox for the permission that is displayed and click Add permissions.


A message will appear that confirms the permissions has been added and it will be listed.


The other configuration is to create a Client Secret which will be for the security of the custom connector for Dynamics 365. Head to Certificates & secrets, click +New client secret and provide a name for the Client Secret. Select the option Never for the expiry setting and then click add.


The Client Secret will be created. Copy the Client Secret value and save it some where as this will be used for the security of the custom connector for Dynamics 365.

How to create a custom connector for Dynamics 365 in Power Automate

Once the App Registration for Dynamics 365 has been created a custom connector can be created in Power Automate. Head to the Power Automate maker site and select Custom connectors. Click on +New custom connector and select the option to Create from blank.


Name the custom connector and click continue.


An icon can be selected to identify the custom connector. In my vlog I was using a Pineapple icon from icons8. A background colour can also be defined. For the Scheme value, leave it as HTTPS.


The Host value will be the organisation part of the Dynamics 365 instance URL.


Click Create connector to create the custom connector before moving on to the Security configuration step.


How to configure the security for the custom connector

Next security for the custom connector needs to be configured. Click Edit and then select the option of OAuth 2.0.


For the Client ID and Client Secret values, copy and paste from the App Registration in Azure Portal. You would have saved your Client Secret some where from the earlier step. Copy and paste the full organisation URL of the Dynamics 365 instance including the HTTPS for the Resource URL value


Remember that Redirect URI configuration field in the App Registration when the App Registration was created? The Redirect URI configuration field in the App Registration needs to be updated with the Redirect URL generated in the Security configurations of the custom connector for Dynamics 365.


Before moving on to creating the custom actions in the Definition step of the custom connector, click Update connector. Always click this whenever you apply any configuration.

How to create Actions for the custom connector

When we use connectors available today in flow within Power Automate, we have the ability to select either a trigger or an action for the connector.


Now that the custom connector has been created, the next step is to create actions which involve providing the API request and JSON Payload of that API request.

1. Creating an action that will generate a PDF

As seen in Stefan Strube's blog post, the Dynamics 365 API request to call that is used by the Dynamics 365 Sales Hub app is the ExportPdfDocument using the POST method. I am using the same JSON payload that Stefan shared but with one adjustment where I am excluding the following highlighted in Red. When I was putting this all together earlier this year I found that it would fail if I included these character references.
{
       "EntityTypeCode": 1084,
       "SelectedTemplate": {
              "@odata.type": "Microsoft.Dynamics.CRM.documenttemplate",
              "documenttemplateid": "153dc496-d79d-e711-8109-e0071b65ce81"
       },
       "SelectedRecords": "[\"{E3A79DA1-9B91-E811-8133-E0071B65CE81}\"]"
}
To create a new action
  1. Click on +New action.
  2. Enter a name.
  3. Enter a value for the Operation ID, I use the same value as the name but all in lowercase.
  4. Click on +Import from sample to create the API request.
  5. Select the method of the API request. In my use case it is POST.
  6. Provide the URL of the API request. In my use case it is
    • https://ORG.crm6.dynamics.com/api/data/v9.1/ExportPdfDocument
  7. Provide the JSON Payload.
  8. Click Import.
  9. Click Update Connector.

My JSON Payload is the following
{
    "EntityTypeCode": 1090,
    "SelectedTemplate": {
      "@odata.type": "Microsoft.Dynamics.CRM.documenttemplate",
      "documenttemplateid": "d2b253f9-5433-ea11-a813-000d3a795c19"
    },
    "SelectedRecords": "4c339def-0c43-ea11-a812-000d3a795c19"
}
  • The EntityTypeCode represents the entity that the PDF will be generated against. In my use case it is the Invoice entity.
  • The SelectedTemplate block represents the Document Template record with the Word Template that the API request will use to generate the PDF. This will be the Document Template record from Part 1: How to create a Word template in Dynamics 365.
  • The SelectedRecords property represents the Invoice record the PDF will be generated against.
To retrieve the EntityTypeCode value of the record for the JSON Payload you can call the EntityDefinition API Request with some filters to obtain the value.
https://ORG.crm6.dynamics.com/api/data/v9.1/EntityDefinitions?$select=LogicalName,ObjectTypeCode&$filter=LogicalName eq 'invoice'
Once the connector has been updated you'll see that your action has been created.

One of the things I love about the custom connector in Power Automate is the ability to test the API request directly within the custom connector configuration. Click on Test and create a new connection to authenticate with the request using your credentials.


Here comes the fun part, the testing! Enter in the property values for the JSON payload. A reminder from earlier what the properties represent,
  • The EntityTypeCode represents the entity that the PDF will be generated against. In my use case it is the Invoice entity where the value is 1090.
  • The SelectedTemplate block represents the Document Template record with the Word Template that the API request will use to generate the PDF. This will be the Document Template record from Part 1: How to create a Word template in Dynamics 365.
  • The SelectedRecords property represents the Invoice record the PDF will be generated against.

To retrieve the Document Template ID value, open the Document Template record of the Word Template to be referenced. Copy the GUID at the end of the record URL.


To retrieve the Invoice ID value of an Invoice record to be referenced, open an existing Invoice record. Copy the GUID at the end of the record URL.


If you test the operation right now it will fail. Remember how we didn't include the extra characters when creating the Request of the action? We need to include some of those characters in the SelectedRecords field. The characters to include is the following highlighted in yellow.
[{"21ce9319-22a3-ea11-a812-000d3a7981c5"}]
[ ] Means make it an array, " " means make it a string, so this is saying make it an array of strings. I interpreted this as the API request likely needs an array of all the GUIDs that you want to generate a PDF for.

Once the SelectedRecords property value has been updated, it's ready to test! The status response should be 200 and you'll see the JSON returned where there is a PdfFile property with a base64 value that represents the encoded PDF file that was generated.

2. Creating an action that will create the PDF as an activitymimeattachment record

Activitymimeattachment is the entity record which will contain information of the attachment such as the encoded base64 value. This forum post explains it well.

The reason why we are using an API request to create the activitymimeattachment record is because today if we attempt to use the Create action from the CDS current environment connector and select the second attachments option when searching for the entity (from memory) the following error will be thrown,
The 'Create' method does not support entities of type 'attachment'.
If you then try the other attachments option you'll still come across a problem as the Item ID is required which can't really be provided since the attachment record has not been created. Therefore I thought of calling the activitymimeattachments API request instead as I learnt from this forum post that the activitymimeattachment should be created first where Dynamics 365 will then create the corresponding attachment record.

Side note: Linn Zaw Win did write a blog post that shows you how to send an email which uses a combination of the CDS standard connector and CDS CE standard connector.

Same steps as before, create a new action, provide a name and operation id value and lastly the JSON payload request. Make sure you click Update connector once the Request has been created.


I worked out the JSON Payload request from this blog post where the following properties are
  • objectid_activitypointer@odata.bind
    • The email activity record to bind the activitymimeattachment
  • objecttypecode
    • The value is email since the activitymimeattachment will be associated to an email activity record
  • body
    • This is the encoded base64 value of what would be the generated PDF. In my WTF vlog I was using this site to generate an encoded sample of  "Hello World. This is a demo"
  • filename
    • This is the file name. It is important in this step to include a reference to the file type. In my WTF vlog I was using a .txt
  • subject
    • This is a descriptive subject for the attachment. In my WTF vlog I used "Hello World" as an example
The next part is testing it out again. To bind the activitymimeattachment to an email open an existing record and copy the GUID from the email record URL.


For the encoded base64 value I used this site to generate a sample value.


Once all the property values have been entered, click test operation. The status response should be 204 and you'll see the JSON returned. Open the email activity record in the Dynamics 365 Sales Hub to double check the file was created and attached to the email activity record 👍

Check the custom connector is visible when creating a new flow in Power Automate

Now that we've learnt how to do an App Registration and create a custom connector with actions for Dynamics 365 we can now check it out in flow! Head to the Power Automate maker site and create a new flow. Once the trigger has been defined add a new action and click on the Custom tab. The two actions created will be displayed and can be selected to add to the flow. Awesome sauce 🙌😄💙

Summary

It's pretty cool that we can create a custom connector for Dynamics 365 if the actions available in the CDS current environment connector will not suffice what needs to be achieved. The beauty of Dynamics 365 and CDS is that the APIs have existed for years and with flow in Power Automate it's now even more easier to perform API requests as the authentication can be configured directly in Power Automate. For PDF automation all it requires is
  1. An App Registration through Azure Portal for the Dynamics 365 instance of the Sales Hub App
  2. Create a custom connector using the App Registration details with custom actions using the Dynamics 365/CDS APIs
Once this is all fine tuned, the custom connector will be available to use in the environment for you to continue making flows in Power Automate.

Thanks for reading this detailed blog post of Part 2 of my automation series. Part 3 will cover all of this in action using actions I've covered in previous WTF episodes.

Your Vote Counts!

If you want Convert to PDF across custom entities then vote for this Dynamics 365 Idea to gain momentum. I would love to see this functionality across the Dynamics 365 platform so let's do our part by voting for it.

via GIPHY

Where my Starship Troopers fans at?! 😁

Tuesday, 9 June 2020

PDF automation series - Part 1: How to create a Word Template in Dynamics 365

If you're a new comer to Dynamics 365, Part 1 covers how to create a Word Template in Dynamics 365.
The API that the Dynamics 365 product team released in 2019 references a Document Template record which has a Word Template associated to it which acts as the backbone of a PDF generated from Dynamics 365. For more information about Convert to PDF refer to this docs.microsoft.com article.

**I'd like to make it clear that as of today, Convert to PDF is configured and supported in the Dynamics 365 Sales Hub app**

In this WTF episode I will cover
  • A brief overview of the Convert to PDF functionality
  • How to create a Word Template from scratch
  • How to update an existing Word Template

Use Case

Before we jump into the How To's, the use case for this series will be

As a customer,

I want to receive a Tax Receipt of my purchase in an email,

so that I have confirmation of my purchase.

The life cycle of the process will be
  1. A Dynamics 365 Invoice record is updated to paid.
  2. A flow in Power Automate is triggered that handles all the magic.
  3. The customer associated to the Invoice will receive an email with a PDF attached that represents their Tax Receipt.

Overview of the Convert to PDF functionality

The Convert to PDF functionality that exists today in Dynamics 365 Sales Hub can be used against the following entities
  • Account
  • Contact
  • Lead
  • Opportunity
  • Quote
  • Order
  • Invoice
This is what it will look like to an end user when viewing a record in the Dynamics 365 Sales Hub app,


Regardless of what option the end user chooses, the end user is required to select a Word Template that has been created for that particular entity. In my case it is the Invoice entity. This is due the Dynamics 365 API request, ExportPdfDocument, as it will generate a PDF based on a Word Template that is associated to a Document Template record. More details regarding the Dynamics 365 ExportPdfDocument API request in Part 2 😉


In order for the Convert to PDF functionality to appear in the Dynamics 365 Sales Hub app they need to be enabled for the desired entities. Head to App Settings and you'll see the Convert to PDF configuration, click Manage.


Enable the entities you'd like and hit that Save button. Refresh your browser and you should now see the Convert to PDF functionality in Dynamics 365 Sales Hub.


Cool on to the How To's.

How to create a Word Template from scratch

Any Word Template or Excel Template created and uploaded into Dynamics 365 will be associated to a Document Template record. This functionality has existed for a few years now and this is the official docs.microsoft.com article.

In my vlog I misbehaved by not showing you how to navigate to Document Templates from the Power Platform Admin Centre - my bad 😅 Old habits since I started with Dynamics CRM 4.0. The following steps will reference the Power Platform Admin Centre.

Head over to the Power Platform admin center and select Settings.


Expand the Templates settings and select Document Templates.


A new browser tab will appear where you click +NEW to create a new Document Template.


Select Word Template and the entity of your choice. In my use case it is the Invoice entity. Click Select entity


Next, the entity relationships are required to be selected in order for data to be displayed in the generated Word document using the Word Template. Since I'm going to be generating a Tax Receipt from a paid Invoice I'll be referencing the Invoice Line Items and information about the customer so I have selected the Invoice Product, Account and Contact entity relationships. Once you're ready click the Download Template button.


Enable Editing on the Word Template and head over to File > Options and in the Customize Ribbon tab enable the Developer command.


Head to the Developer tab and select the XML Mapping Pane from the ribbon. This is where we can define the XML Mapping to the Invoice entity in Dynamics 365. Select the Custom XML Part drop down field and there should be a reference to the Dynamics 365 entity that was defined when the Word Template was downloaded from Dynamics 365.


Once the XML Mapping is pointing to Dynamics 365 reference the fields for the Invoice entity will be displayed.

If you scroll down the entities based on the entity relationships defined for the Word Template will also be visible which will allow you to select the fields from those entities.


You can start creating your desired Word Template by selecting a field from the entity relationships. For example to select the Invoice Number field from the Invoice record,
  1. Scroll down to the Invoice Number field.
  2. Right click and select Insert Content Control.
  3. Select Plain Text.
This will display your select field where you have positioned it in the Word document.


Continue to build the rest of your Word Template to your requirements. If there will be a table in your Word Template, you'll want to display the rows of that related data. In my use case this will the Invoice Line Items. Previously we were selecting fields but since we're dealing with rows for a table the content control is sightly different.

Create a table and in your first row select the content controls for the fields. Then highlight your first row, select the entity from the related entities and right click to select insert content control followed by "Repeating."


When the Word Template has been defined it can be uploaded into Dynamics 365. Save your Word Template and head back to the Document Templates view to create a new Document Template record.


Select your Word Template file to upload.


Click on Upload.


A new window will appear with the newly created Document Template record. By default the file name will be the value in the Name field. This can be updated to whatever value you like.


To check out your newly created Word Template, open an existing Invoice record and select the Word Template to see it in action.

How to update an existing Word Template

If you were to open a Word Template record in Dynamics 365 you won't see anything that indicates a way of updating the previously uploaded Word Template.


The solution? XrmToolBox. Microsoft MVP Tanguy Touzard is the legend behind XrmToolBox and there are many people in the Microsoft community who have contributed their time by creating and adding tools to XrmToolBox. One of these souls is Microsoft MVP James Novak who created and shared his tool called "Document Template Manager" which allows you to download existing Word templates and edit them.

When you open XrmToolBox head over to the Tool Library and select Document Template Manager to install.


Once it has been installed and select the Document Template Manager Tool which will connect to the environment that you were last connected to.


If you are not connected to an environment already you can select an existing environment or create a new environment in the "Connected To" settings of XrmToolBox which will be at the bottom on the left.


To load all the templates available in the Dynamics 365 instance you are connected to click on the Load Templates button. To update one of the out-of-the-box Word Templates such as Invoice Summary, select the document and click on Download Templates.


Once the Word Template has been downloaded you can open the file and view the existing template with the references to the content controls that have been defined. If you want to add any additional content controls, head to the XML Mapping Pane in the Developer tab of the ribbon. Select the Custom XML Part drop down field and there should be a reference to the Dynamics 365 entity that was defined fro the Word Template.


When you're ready to upload the Word Template document you can do this directly from Jim's Document Template Manager tool as well. Select the Word Template you want to overwrite with your updated template and select Single Upload. A warning message will appear to inform you that the file uploaded will overwrite the document template for that select Document Template record.


Once it has completed you can then navigate to your Invoice record and select the updated Document Template record.

Summary

You can either create a Word Template from scratch or create a Word Template based on an existing template by downloading it through XrmToolBox using Jim's Document Template Manager tool.

A Document Template record will be referenced in my flow in Power Automate that will generate a PDF of an Invoice automatically. Stay tuned for Part 2 where I will share how to create a custom Dynamics 365 custom connector to handle the API request to generate the PDF.

Your Vote Counts!

If you want Convert to PDF across custom entities then vote for this Dynamics 365 Idea to gain momentum. I would love to see this functionality across the Dynamics 365 platform so let's do our part by voting for it.

via GIPHY

Where my Starship Troopers fans at?! 😁

Monday, 8 June 2020

Upcoming PDF Automation 3 part series - generating a PDF and emailing it automatically

I have an upcoming PDF automation series series where I'll be breaking down how to automate generating a PDF and emailing the PDF.

By the end of the series you'll be able to understand how to create your own Word template in Dynamics 365 that can be used for the automation of generating a PDF and attaching it to an email that can be sent out to the customer through a custom connector for Dynamics 365.

Stay tuned! Don't forget to subscribe to my YouTube channel so that you don't miss out 🙂

Thursday, 16 April 2020

Sending an email from a Queue with Power Automate

When using the native email message capability of CDS or Dynamics 365, there are two options that can be used as the sender
  1. A system user - this is achieved from a licensed CDS or Dynamics 365 end user that also has the relevant Office 365 subscription 
  2. A queue - this is achieved from a queue that has been configured against a shared mailbox in Exchange

When would you use one over the other?

It depends on your business use case. If you have a team managing incoming emails where the entire team needs visibility, a queue is appropriate. This is typical in customer service centres or insurance claim teams where enquires, cases, support and so forth is emailed to a shared mailbox.

If you're a manager and you want to remind your colleagues in your team that they have not submitted their time sheet for dates of the week, a system user is appropriate.

In this WTF episode I'll be covering how to send an email from a Queue using flow in Power Automate as I've covered sending from a system user in previous WTF episodes.

Setting up your Queue in CDS or Dynamics 365

One of my friends who is also a Microsoft MVP, Megan Walker, has already done a blog post of how to set up a queue and send from a queue in classic workflows.

I'll reiterate her instructions in my own words and share what I usually do.

The steps I'm about to share is under the assumption that
  • the end user has the relevant licences for CDS or Dynamics 365 and Office 365
  • the end user has the relevant security role in CDS or Dynamics 365 to create a queue and set up the mailbox profile
  • the end user also has the relevant Office 365 permissions to set up a mailbox
If the end user's organisation has an IT ops or infrastructure team in-house (or even external party) then it's best for those teams to handle it in case they have policies set up. I have made the mistake in the past where I do it myself and when it comes to testing it doesn't work so then I hand it over to the organisation's in-house team or external party. Best to check first.

1. Create a shared mailbox in Office 365

The first thing I do is create a shared mailbox in Office 365 where I also add the relevant users to the mailbox as well.


For really good instructions on how to do this plus additional configuration, refer to this docs.microsoft.com article.

2. Configure the environment email settings

Head to Power Platform Admin Center and click on the . . . (aka ellipsis) against the environment you're going to be sending the email from. 


Expand the Business Settings and you'll see the Email Settings option. Select this option.


In the Outgoing Emails setting, select server-side synchronisation.


Cool, on to the next task.

3. Create a queue in CDS or Dynamics 365

Once again head to Power Platform Admin Center and click on the . . . (aka ellipsis) against the environment you need to create the Queue in. Expand the Business Settings and you'll see the option called Queues. Select this option.


Click on +New to create a new Queue record and fill in the fields.



For more configuration details of Queues please refer to this docs.microsoft.com article.

3. Configure the Shared Mailbox

In the Queue record, there will be a command called "Open Mailbox." 


Select this option which will launch a new window that displays the mailbox associated to the Queue. Set the Outgoing Email to Server-Side synchronisation and double check the email address is the same as the shared mailbox email address.


The final steps you want to do is
  1. Click Approve Email
  2. Click Test & Enable Mailbox

Head back to the Power Platform Admin Centre and head into Email Settings again. Select the Mailboxes option.


In here you should see that the mailbox has successfully been enabled.


If your shared mailbox profile in CDS or in Dynamics 365 was not successfully enabled, please raise a new support request through the Power Platform admin center for assistance with your environment.

4. Test your Shared Mailbox works

I don't stop after I configure the Shared Mailbox because experience has taught me that until you perform an outbound email from the Queue, it's not all green! I tripped up years ago when I didn't perform a test myself and since then have always tested my outbound emails after completing the set up and configuration of a Queue.

Create a new email message activity in CDS or Dynamics 365 and update the From field to the Queue you created. Also make sure you are selecting either a user (in other words a colleague) or a test contact as the recipient in the To field because if the email sends, it will send so do not use a real customer email address.


Hit send and the status should eventually update to Completed. Check with the recipient that they have received the email.

Sending from a Queue in a flow with Power Automate

Once the queue is all good to go, the queue can now be used as the sender for email messages. This is what my flow in Power Automate for this WTF episode looks like.

1.0 Trigger is when a Case is created

The trigger will be the same as WTF episode 21 where it will be when a Case is created.

Use the CDS List records action

The technique I shared with you in my WTF vlog is one I do use as it's one of those things that years have experience has taught me. Yes you could explicitly reference the GUID of the queue in your flow but that can result to deployment issues. Why? Chill for a couple of minutes and let me spill the tea #teatime

There may be times when a queue was not migrated from DEV to a target instance such as UAT. The queues will have different GUIDs which will cause either your flow in Power Automate or classic workflow to fail. To get around this in flow, use a CDS List records (current environment connector) with a query to the name of the queue. This means you need to create your flow in a solution in Power Automate to use the current environment connector.


I did warn during the WTF vlog this should work but there is a chance that for whatever reason the queue in the target instance may not have the same name as the originating instance. In this scenario you're going to have to use another type of query that will work for you.

Hack time

I feel like John Liu in this part of the blog post lol. This is #flowninja hack 115 😁
If you don't know what I am referring to, you must follow him on Twitter to understand his tweets on hacks he shares for flows in Power Automate 🐱‍👤💙

Currently there is a known issue where some entities will return a 200 status response instead of the full JSON response which makes it hard to validate if your CDS List records (current environment) action has correctly retrieve the correct record(s). My hack as a workaround right now is to use a Compose action and reference the body of the CDS List records (current environment) action. This will then give you the JSON response which you can review in Visual Studio Code or Notepad++ to confirm the correct Queue record was retrieved.

Final step - perform an unbound action

In WTF episode 21, the CDS action (current environment) used was the perform an unbound action where the action is SendTemplate. Same unbound action is used in this WTF episode and in the Sender field of the action, the queue is referenced instead of the system user. This is the difference when sending from a queue through a flow in Power Automate.


My expression to reference the queueid is

outputs('1.1_Retrieve_queues')?['body']?['value'][0]?['queueid']

This expression will prevent the Apply To Each from appearing which I covered in WTF episode 20.

Power Automate in action

Good to go, trigger the flow and away it goes in Power Automate! The sender will now be the Queue rather than a user.

Summary

Like classic workflows, queues can also be used as the sender of emails in flows with Power Automate which is what I shared in this WTF episode. The following is a checklist in order for queues to be used as the sender,
  1. A shared mailbox has been set up
  2. The email settings for the environment have been enabled to allow outbound emails
  3. A queue is created in Dynamics 365 and the mailbox profile has been configured to use the shared mailbox
  4. A test outbound email has been created and successfully sent
Thanks and don't forget to subscribe to my YouTube channel and hit the notification bell so that you don't miss out on my next WTF episode 🙂