Previously, we looked at how to create and train AI models using AI Builder in Power Apps and how it can be embedded in an app in these four blog posts:
- AP Automation using AI Builder in the Power Platform
- Using Category Classification AI to Identify the General Ledger Account
- Using a Power Apps app with AI Builder Models to Capture a Vendor Invoice
- A Closer Look at How I Use AI Builder Models Inside a Power Apps App
In this blog post I am taking a closer look at how we can use Power Automate to take the data captured in the app and submit it to Dynamics 365 Finance.
As you may recall from the previous blog post, the Power Automate flow is called when the user clicks on the save icon in the app to submit the invoice data to Dynamics 365 Finance.
As you can see from the above screenshot, the flow is triggered by Power Apps as you would expect. Subsequently, I initiate a number of variables that I need further down the flow. Some variables, for instance Amount and MainAccount are passed from the app.
Since the VendInvoiceJournalLines data entity in Dynamics 365 Finance has separate debit and credit fields, I create a condition to set the variables based on the amount received from the app as shown below.
Since this flow is used both for creating invoice journals (this example) and general ledger journals, I need a condition to determine if it is one or the other. In this case, I make the distinction based on whether an off-set account was passed from the app.
In this example, we do have an off-set account, so the condition will go down the No path.
The first step we make to create an invoice journal in Dynamics 365 Finance is to create the journal header.
As you can see, I am using the standard Dynamics 365 Finance and Operations connector (OData) in Power Automate to create the header. The Name attribute is set to “APInvoice”. This is a journal name I have set up under General ledger / Journal setup / Journal names as shown below.
The data entity is designed in a way that it will automatically draw the next journal number from the number sequence.
Why did I use the invoice journal instead of the invoice register or pending invoices? In this example where the user is also the approver, I assume the invoices can be posted without any further review.
Next step is to create the invoice journal line.
As you can see, the Journal batch number field is filled in by a placeholder holding the journal number value generated when we created the journal header.
If I expand the connector by clicking on Show advanced options, I am able to fill in the remaining fields in the data entity. To make this example work, I fill in the following fields:
|Document||Invoice number from app|
|Account||Main account from app|
|Offset account||Main account from app.Cost centre from app*|
|Invoice||Invoice number from app|
* Please note, the off-set account must respect the format set up in Dynamics 365 Finance under General ledger / Chart of accounts / Dimensions / Financial dimension configuration for integration applications.
** Expression used to set timestamp with current date and time.
Lastly, I capture the voucher number created for the line in a variable as we will need it later in the flow.
The last major step in the flow is to store the invoice image and alert the app user.
Firstly, I have inserted a condition to check if there is actually an image included. If not, we do nothing.
In the first step, I use a Compose action to convert the image format received from the app to a binary format.
Subsequently, I store the binary image content in BLOB storage in Azure.
As you may have noticed, I am using the voucher number for the file name. This makes it easier for me to identify the image later on.
In the last step, I notify the user using Outlook 365.
So what does the result look like?
The above screenshot shows the journal header created by the flow.
If we open the journal, we can see that a journal line has been created using the information we captured in the app.
As you may have noticed, the screenshot contains a tab named Invoice image. This is not a standard tab. However, I have added the tab using personalisation.
When I click on the tab, the invoice image stored in Azure BLOB storage earlier on is displayed. This is achieved by embedding a Power Apps app in the user interface using personalisation.
In my view, this is a great example of how we can extend the Dynamics 365 Finance user interface without writing customisations.
You can read more about user interface personalization here.
This concludes this short series on how to leverage AI capabilities with Dynamics 365 Finance using the Power Platform. I hope you found the information useful.