QR Code with Microsoft Dynamics NAV App

An interesting extension of the Microsoft Dynamics NAV Phone app has to do with the ability to retrieve pictures using the device camera, where available. This feature is duly described in MSDN: How to: Implement the Camera in C/AL

If you would like, then, to scan QR codes and Data Matrix in order to have an overview of the item assigned to that code, this could be easily implemented with a process close to the following:

  • Take a picture
  • Picture is saved server side
  • A .NET Assembly (QR Code reader) scan QR Code and return the string decoded
  • The string decoded is now actionable (e.g. open Item card)

How this could be done in practice?

1. Develop your own .NET Assembly to read QR Code

In this example, I have used the well-known ZXING library available on github.com.
See references below for documentation and usage disclaimer:

Just create a simple Visual Studio Solution that reference zxing and zxing.presentation libraries, accordingly to the target .NET Framework for your solution (e.g. .NET 4.5).

And code against them to have an image decoded as per the following

2. Deploy your .NET assemblies

Deploy the assemblies both server side and – for development only – client side in the Add-Ins folder. These are the relevant files that you have to place in the Add-Ins folders:

3. Create a QR Code Management code unit

In the Development Environment, create a new Codeunit called “QR Code Management” – or whatever you like - and add the following global function. DotNet data type runs as per default server-side.

4. Add QR Code to the Item table

Add a field in Table 27 “Item” called “QR Code” and map that field to both Page 30 “Item Card” and Page 31 “Item List”

5. Code!

Now, it is time to implement the MSDN coding to take a picture and store it server side.
Add the following code in Page 31 “Item List” OnOpenPage trigger

And create an action named “ScanQR” with the following properties and code

Last, but not least, when the PictureAvailable event is fired, implement some code that moves the picture into a specific folder – for better handling –, scan QR Code content and run the specific Page 30 “Item Card”, if this is recognized.

NOTE: images are never erased in C:\TEMP folder. Prepare your own batch/routine/ PowerShell script for an easy clean-up of the directory. If you have deployed IAAS solution using Microsoft Azure VMs, you might think of moving the images in the Temporary Storage disk (D:).

Have a good scan!

These postings are provided "AS IS" with no warranties and confer no rights. You assume all risk for your use.
Duilio Tacconi (dtacconi)
Microsoft Dynamics Italy
Microsoft Customer Service and Support (CSS) EMEA

Comments (8)

  1. Dmitry Katson says:

    Thanks. However this will not work with new dev environment and extension for D365, cos they don’t support external .NET libraries?

    1. Andrew Cowan says:

      As it stands it won’t work. Microsoft have been pretty adamant they aren’t going to support external libraries. I think you may have to use the standard NAV camera functionality and an external webservice (eg. Azure WS)- you can then use the c# code above in an asp.net application.

    2. dtacconi says:

      @Dmitry. This is intended only for CSIDE – of course – since at the moment with D365FF / Extensions V2 you cannot deploy .NET assemblies. There are 2 ways, then, to resolve QR Code / Data Matrix scanning, in my opinion. First one is service based. You might find a couple of web services that accept to stream the picture object and returns a decoded string. You could engineer to create a Wizard that setup connection to that web service (in the Modern Dev Azure VM image in \New Developer Experience\Samples you\GetAddressService you could find a good example). The second one – that probably I would like to give it a spin and publish it if I succeed – is to use the same C# snippet within the context of Azure Functions and create an extensions that setup a connection to that Azure Function. In this way you create your own Web Service to decode the string.

  2. Arvydas says:

    Hungarian notation could not be unseen

    1. dtacconi says:

      @Arvydas. I know, I am guilty. I will redeem in the next blog post with CamelCase variable declaration. Morevoer, I have called C# function and this might be another point – if you haven’t noticed yet -. The fact here is that I was so happy to make it work in so short time that I have provided snippets as is. Literally, I have spent half-day scanning all possible QRs that I had around.

  3. Ahmed Mihoub says:

    Thanks for this post, it work but there is a big problem that the QR decoded is not all the time recognized even i m using an 8 Mega Pixel samsung s6 or Lenovo tablet (1 Mega Pixel), when i debugg the .Net Assembly to find why it return an empty decoded string i have this error “object not set to an instance of an object”

    ps : Tested on Dynamics NAV 2016

  4. Nam Nguyen says:


    It work well with QR code from images. But it rarely work with the images which captured from camera.

Skip to main content