A Closer Look at How I Use AI Builder Models inside a Power Apps App

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:

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.

Power Automate flow is triggered by Power Apps

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.

Set debit / credit fields based on amount sign

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.

Condition to determine the type of journal

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.

Create invoice journal header in Dynamics 365 Finance

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.

Journal name set up in Dynamics 365 Finance

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.

Create the invoice journal line in Dynamics 365 Finance

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:

CreditCredit variable
DocumentInvoice number from app
Document dateutcnow()**
AccountMain account from app
Offset accountMain account from app.Cost centre from app*
DebitDebit variable
InvoiceInvoice number from app
Addition fields required to create invoice journal line in Dynamics 365 Finance

* 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.

Set voucher variable

The last major step in the flow is to store the invoice image and alert the app user.

Store image and notify 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.

Convert image string to a binary format

Subsequently, I store the binary image content in BLOB storage in Azure.

Store image in Azure BLOB storage

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.

Notify user through e-mail

So what does the result look like?

Invoice journal header created by the flow

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.

Invoice journal line based on captured information

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.

Embedded Power Apps app displaying the invoice image

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.

Published by Henrik Marx Larsen

This blog is my personal contribution to the Microsoft Dynamics 365 for Operations and Finance (D365F&O) community debate. Having worked with Axapta / Dynamics AX / D365F&O for 20 years , I think I may have some interesting insights and views to share. However, I tend to always look forward so I will mostly be writing about current subjects. I have a vain hope that my musings may inspire some of you and provoke some new thoughts in the interest of our community. My day job is to work as a Senior Technical Specialist at Microsoft and help take D365F&O capabilities to new and existing customers. Please note, the views expressed in this blog are mine alone and do not necessarily reflect the views of my employer, Microsoft.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: