Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Blogs / Learn with Subs / Attach documents to D365F&O...

Attach documents to D365F&O records using Azure AI Document Intelligence Studio

Subhad365 Profile Picture Subhad365 7 User Group Leader
Hiya friends!!!
Let me introduce a cool hack by Azure AI document intelligence Studio, using which you can attach documents to D365F&O records (e.g.: Purchase Orders, sales orders). Azure AI Document Intelligence is an AI service that applies advanced machine learning to extract text, key-value pairs, tables, and structures from documents automatically and accurately. Turn documents into usable data and shift your focus to acting on information rather than compiling it. Start with prebuilt models or create custom models tailored to your documents both on premises and in the cloud with the AI Document Intelligence studio or SDK. Document Intelligence (aka Form recognizers) are amazing AI services which you can train with document pattern of the particular template you want to envisage and then you can use the training module to interpret/analyse any new document.
As an example, here we are going to attach a Purchase Order Image to a Purchase order record. Let us assume the document does have somewhere: Order # inscribed. Document intelligence will read and understand the inscription and attach it to the F&O record.
Let us see how this could be done.

Step 1

Step 1: Create a Document intelligence API: Go to https://portal.azure.com and create a new Form recognizer resource:


For our demo purpose we are selecting 'Standard' pricing tier. Alternately you can also select Free tier, if needed.
Click 'Preview + create' >> Create finish the wizard. It will take few moments to create the resource. Come to the resource thus created and note the endpoint and access keys associated:


Click on 'Go to document intelligence studio'. It will open a new page where by default you can see a lot of options:


Click on 'Invoices' >> This will give you the following option to upload your image invoice:

On the 'Browse file', let us upload an invoice image like this:



After upload, the document intelligent will show the image preview like this, identifying all the embdded literals/words/figures:




Click on Run analysis. It clearly shows all the readable words/figures now:


Click on 'Content', it shows all the embedded table:


Click on Result tab. You can get the JSON associated with it, that contains each and every word, treating it as a 'control', along with its coordinates and the confidence with which it can identify the control. Let us inspect this JSON thoroughly, as we understand it very well. 

Step 2

Let us create a Doc intelligence Project now, to start with the training of the model:

 Click on Custom model >> Create new project:

This will come up with the following pop-up:

Give a project name and a proper description. Click on Continue:

In the following screen, choose the subscription, resource group and API version. Do select it as: 2023-10-31, as this is the latest that is recognized by Power Automate (we shall see later).
Click on continue. In the following screen, select the following details:

These are all what are necessary for training and configuring the associated data sources, that it will need for training.
Click on Continue.
The following screen comes as a last step to Finish off the project creation:

Click on Create Project to finish off.

Step 3

Now we will be actually training the model. The following screen will appear where you can ‘Label’ the data:

Click on Browse for Files and upload an image document for your Purchase Orders:

Click on ‘Auto label’ to make the model understand which data belongs to what label (e.g.: there is a label called PO#, there is a label called invoice #, etc.) . Click on Auto-Label. The following will pop-up:

Click on ‘Prebuilt-invoice’, whereby it will understand this document as an Invoice document and will try to find what are the typical labels that could be found in an Invoice document:
 And in no time, you could see all the labels that its has found:

You can define your own labels, by clicking on Add a Field:

You can define your own field:

And then when I am clicking on Line amount, it will come automatically with the pop-up to select the Label that you want to associate it with. I am selecting LineAmount as label to the field:

Keep doing this activity for as many field-labels you want to do. And then once you are done, click on Train to start the training:

This will start the training of the model. Once it’s done, you can test the model by clicking on Test Tab, and uploading a new document:

Click on Run Analysis and it will give all the labels (for example: PO# and invoice total amount):

Step 4

Now we will leverage this model from Power automate. To begin with, as an example, I have created a very easy trigger that responds to incoming mails to a particular mailbox that contains attachment, and subject contains ‘Purchase order’:

Along with that I have created a litter of variables to contain PO#, filename, contents and AAD tokens.
And then in the next steps, I am getting the content of the file and calling the Form Recognizer services as is highlighted:

In order to set this up, you need to get the Endpoint and Keys from the Azure AI Document intelligence which you created from the Step 1:

Essentially this is what is responsible for parsing the JSON response after reading the file and lookin for Purchase Order #, which I am storing in the purchId variable:

That’s pretty cool, right? Generally the response from the Doc intelligence comes in a JSON payload, but here, you don’t even need to parse the JSON – just search for the label you’re looking for, and assign it in a variable – for later reference. Here are some more parts of the response from the JSON from Analyse invoice:

Step 5:

Rest is very simple. Simply call the OData endpoint of D365F&O, by obtaining the token and attaching it as an Authorization bearer token:

And in the body you can send all that is needed for attachment creation:

Once the workflow gets triggered – it successfully attaches the file to the target purchase order.
This is the purchId variable, seen from the run history:
 
And this is the attachment to the purchase order:

That’s it guys 😊
That was just an example. You can extend the capabilities of Document intelligence to myriad avenues:
  1. Reading hand written bills to create expense journals
  2. Creating orders from image documents
  3. Attach documents, as shown above
  4. Understand the pattern of any invoice format and decide if it’s a proforma or packing slip or invoice
With that let me take your leave. Would be back soon with similar cool hacks from Azure AI services with D365F&O. Stay in touch and namaste 😊

Comments

*This post is locked for comments