Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Blogs / Learn with Subs / Read invoice receipts using...

Read invoice receipts using Document intelligence APIs, with Azure Logic Apps

Subhad365 Profile Picture Subhad365 5 User Group Leader

Azure AI form intelligence is a wonderful way of reading image invoices. You can now create a document intelligence API and pass on an image document, with preseiely reading embdded words, figures and everything. They return contents in both literature as well as JSON based contents. And guess what? Whenever there is a JSON based content involved, obvously you can leverage them on Azure middlewares like Azure Logic Apps, can't you?
Reading such a JSON response could be tricky. And this document can give you a fair idea to achieve this.
And here are the steps:
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 embeded 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 gotta understand it  very well. 
Copy the JSON and paste it in https://jsoneditoronline.org/#left=local.bazeza&right=local.zowiqo
and click on Beautify it. You will get the schema like this:

Which implies under the \\analyzeReult\\readResults >> 0th node >> lines>>from 17th Node onwards our lines details would start.

We need to devise our parsing structure in such a way, that it starts from node number 18.

Step2: To do this, we can design a logic app, that is capable of reading from an added blob from a storage container like this:



I am using a variable to store the path of the blob and a counter variable, which I would be needing later. 
Step 3: Next, add a 'Form recognizer' action with the details which you can get from Azure portal.

Give a name for the connection.
Account Key you cam get from the access key of the resource which you  created from step-1.
Endpoint URL: you can get from Azure portal. 
Use the output of the above step, it will look like this:

Step 3: Use two For-each loops, one for the outer loop to reach till \\analyzeReult\\readResults >> 0th node >> lines:




And the next one to loop through each item of the Lines:

Step 4: Next increment the counter variable declared above by one:

With a condition to consider only all the lines which have value greater than or equal to 18:

If true, then get the value from 'text' node, by parsing the json, and if false just ignore it:

Whew! Our Logic app is now ready. If you now put the invoice of this kind of sturcture in the Azure blob, it will very easily be able to take out the value of the associated line wise items:


The above screenshot is showing from node 18, the values of the line wise items are showing, as expected:

So the bottom line is: you need to manually find out from the output JSON file from where (which node onwards) the actual line-wise item variables are coming and you can use the same in your for-each loop accordingly.

Comments

*This post is locked for comments