QR Codes for Microsoft Dynamics NAV


QR codes (abbreviated from Quick Response code) are appearing in many different places today, and they are found to be quick and efficient when it comes to working with mobile phones and other devices which can read them. QR Code is a multipurpose instrument and it can hold all sorts of different types of valuable information like your company’s or your salesperson’s contact details, sales invoice information, promotional codes, location information, checksums, amounts, web links etc., which you can read using a QR code reader to automate some of the routine manual processes, like typing in things manually. 

The QR code is a two-dimensional data-matrix which can be decoded very fast. The format is clearly defined and published as an ISO standard.

QR code

As the Windows Phone 7.5 update, code name “Mango”, rolls out to customers, it makes it even more relevant to use the QR codes, as you can now use your Windows phone camera to scan QR codes by bringing them into camera view. Bing will recognize QR codes and will help you save and use the information encoded in it.

In some countries, popularity of QR codes has grown so much, that their usage is now considered a national standard. Our team has recently released an update for the Mexican market, where we added QR codes to several major Microsoft Dynamics NAV documents. And we thought – why don’t we let everyone else enjoy this new cool feature?

The update is available for NAV 5.0 SP1, NAV 2009 SP1 and NAV 2009 R2 versions of the product.

URLs for Microsoft Dynamics NAV 2009 SP1 and R2:

https://mbs.microsoft.com/customersource/downloads/taxupdates/MSDNAV2009SP1ElectronicInvoice_Mexico   

URLs for Microsoft Dynamics NAV 5.0 SP1 :

https://mbs.microsoft.com/customersource/downloads/taxupdates/MSDNAV5SP1ElectronicInvoice_Mexico

However, the only part you need from it is the MXElectronicInvoice.msi file included in the package. Note that the .msi file is exactly the same for both versions of NAV.

Here is what you have to do to get your data encoded into a QR code:

1. Run the installer to deploy the dll we shipped for this update. Among other things, the dll includes QRCodeProvider  and IBarCodeProvider classes which we can use.

2. Add a BLOB field which will be storing the QR Code image into the Sales Invoice Header table for example:

3. Remember to set the SubType property to Bitmap if you would like to use the QR code on pages:

4. You can now use the following code to generate a QR code image, which for demo purposes will be saved into a first found posted sales invoice (needless to say, you should be doing it on a test database 😉 ) In this example we will encode a contact card with some predefined details.

OBJECT Codeunit 50001 QR Code Mgt.
{
  OBJECT-PROPERTIES
  {
    Date=;
    Time=;
    Modified=Yes;
    Version List=QR Code;
  }
  PROPERTIES
  {
    OnRun=VAR
            CompanyInfo@1170000004 : Record 2000000006;
            SalesInvoiceHeader@1170000003 : Record 112;
            TempBlob@1170000002 : Record 99008535;
            QRCodeInput@1170000000 : Text[1024];
            QRCodeFileName@1170000001 : Text[1024];
          BEGIN
            // Save a QR code image into a file in a temporary folder
            QRCodeInput := CreateQRCodeInput(‘John,Doe’,’+555 1231231′,’john@doe.zzz’,’www.johndoe.zzz’);
            QRCodeFileName := GetQRCode(QRCodeInput);
            QRCodeFileName := MoveToMagicPath(QRCodeFileName); // To avoid confirmation dialogue on RTC

           // Load the image from file into the BLOB field
            CLEAR(TempBlob);
            ThreeTierMgt.BLOBImport(TempBlob,QRCodeFileName,FALSE);
            IF SalesInvoiceHeader.FINDFIRST THEN BEGIN
              SalesInvoiceHeader.”QR Code” := TempBlob.Blob;
              SalesInvoiceHeader.MODIFY;
            END;

           // Erase the temporary file
            IF NOT ISSERVICETIER THEN
              IF EXISTS(QRCodeFileName) THEN
                ERASE(QRCodeFileName);

            MESSAGE(‘Done!’);
          END;
  }
  CODE
  {
    VAR
      ThreeTierMgt@1170000001 : Codeunit 419;

    LOCAL PROCEDURE CreateQRCodeInput@1020046(Name@1020000 : Text[80];PhoneNo@1020002 : Text[80];EMail@1020003 : Text[80];URL@1170000000 : Text[80]) QRCodeInput : Text[1024];
    BEGIN
      QRCodeInput :=
        ‘MECARD:’ +
        ‘N:’ + Name + ‘;’ +
        ‘TEL:’ + PhoneNo + ‘;’ +
        ‘EMAIL:’ + EMail + ‘;’ +
        ‘URL:’ + URL + ‘;’;
    END;

    LOCAL PROCEDURE GetQRCode@1020038(QRCodeInput@1020001 : Text[1024]) QRCodeFileName : Text[1024];
    VAR
      IBarCodeProvider@1020000 : Automation “{89F54BC4-E6C9-44BA-8574-86568625BFF8} 1.0:{9FE38730-1A3C-4B84-A8C2-AFAC6A90E641}:’Microsoft Dynamics Nav MX Services’.IBarCodeProvider”;
    BEGIN
      GetBarCodeProvider(IBarCodeProvider);
      QRCodeFileName := IBarCodeProvider.GetBarCode(QRCodeInput);
    END;

    PROCEDURE GetBarCodeProvider@1020001(VAR IBarCodeProvider@1020000 : Automation “{89F54BC4-E6C9-44BA-8574-86568625BFF8} 1.0:{9FE38730-1A3C-4B84-A8C2-AFAC6A90E641}:’Microsoft Dynamics Nav MX Services’.IBarCodeProvider”);
    VAR
      QRCodeProvider@1020002 : Automation “{89F54BC4-E6C9-44BA-8574-86568625BFF8} 1.0:{69FEA5E6-0A76-4555-B74B-F170956B0098}:’Microsoft Dynamics Nav MX Services’.QRCodeProvider”;
    BEGIN
      IF ISCLEAR(QRCodeProvider) THEN
        CREATE(QRCodeProvider,TRUE,TRUE);
      IBarCodeProvider := QRCodeProvider;
    END;

    PROCEDURE MoveToMagicPath@1170000000(SourceFileName@1170000000 : Text[1024]) DestinationFileName : Text[1024];
    VAR
      FileSystemObject@1170000001 : Automation “{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 1.0:{0D43FE01-F093-11CF-8940-00A0C9054228}:’Windows Script Host Object Model’.FileSystemObject”;
    BEGIN
      DestinationFileName := ThreeTierMgt.ClientTempFileName(”,”);
      IF ISCLEAR(FileSystemObject) THEN
        CREATE(FileSystemObject,TRUE,TRUE);
      FileSystemObject.MoveFile(SourceFileName,DestinationFileName);
    END;

    BEGIN
    END.
  }
}

5. With the image saved in the BLOB field, it is now “business as usual” to add it to a report. You can see, for example, how company logo is added to the standard NAV document reports. NB. Don’t forget to run CALCFIELDS on the “QR Code” field before you display its content. 🙂

6. And finally – run the report to see the QR code which you or your customers can scan, for example, with your favorite  Windows 7.5 mobile phone:

 

These postings are provided “AS IS” with no warranties and confer no rights. You assume all risk for your use.

 

Best regards,

Microsoft Dynamics NAV ERM Team

Dmitry Chadayev, Program Manager

Comments (32)

  1. Natalie K. says:

    Thanks for bringing it to our attention! 🙂

  2. Mike_Glue says:

    Thanks! Does anyone know what input strings to create for the various types of QR Codes? For example, map links, calendar events, etc.

  3. Hi!

    Composing Bing Map links is well explained here:

    social.msdn.microsoft.com/…/1ee6dfc4-b4cd-4bfc-a3ad-71acf80c61c3

    Here is for example a url which being embedded into a QR code will get you to the Little Mermaide in Copenhagen: http://www.bing.com/maps

    Composing calendar items and events can be different depending on a QR code scanner, therefore I have no generic solution here. Here is a link which might be helpful: support.microsoft.com/…/287625

    Best regards,

    Dmitry

  4. Hi, Thnaks for sharing. it is very good.

    just a little question on it, how can we control the picture size when generate the QR barcode?

    Thanks.

  5. Søren Alexandersen says:

    Hi Dmitry

    Excellent post.. thank you very much.

    Will the same automation be able to print a data matrix barcode too?

    qrworld.wordpress.com/…/qr-codes-versus-data-matrix

  6. Hi Søren, thank you!

    This feature was released based on a legal requirement in Mexico. Currently we don't have plans changing the component to support other types. But the possibility of supporting creation of data martices sounds quite interesting! …especially when you need smaller labels printed for small items. Very good suggestion.

    Best wishes,

    Dmitry

  7. ngc says:

    Would this also work with Nav 2013? I badly need to include QR codes in our asset management system.

  8. Dmitry says:

    I don't see why wouldn't it work there too. This is an external DLL which accepts text and produces image. You can certainly give it a try 🙂

  9. Cc says:

    cAN YOU PLEASE SUGGEST ME A WAY TO CHANGE QR CODE IMAGE SIZE. PLEASE REPLY.

  10. ngc says:

    Our Navision partner is telling me that it is only possible to use these QR codes with the extended pack version of Nav 2013. We only have the starter pack. Is this true?

  11. Grigoriy A. says:

    For resize qr-code can use this function from mibuso (http://www.mibuso.com/dlinfo.asp)

       PROCEDURE ResizeBMP@1000000001(CurrentPathName@1000000001 : Text[1024]);

       VAR

         BMPfile@1000000000 : File;

         SetResolutionValue@1000000002 : Integer;

       BEGIN

         BMPfile.TEXTMODE := FALSE;

         BMPfile.WRITEMODE := TRUE;

         BMPfile.OPEN(CurrentPathName);

         {CASE PrinterResolution OF

           1: SetResolutionValue := 23622;

           2: SetResolutionValue := 11811;

           3: SetResolutionValue := 5905;

           4: SetResolutionValue := 0;

         END;

         }

         SetResolutionValue := 950;

         //Write horizontal resolution

         BMPfile.SEEK(38);

         BMPfile.WRITE(SetResolutionValue);

         //Write vertical resolution

         BMPfile.SEEK(42);

         BMPfile.WRITE(SetResolutionValue);

         BMPfile.CLOSE;

       END;

    calling function:

    OnRun()

    // Load the image from file into the BLOB field

    CLEAR(TempBlob);

    ResizeBMP(QRCodeFileName);//ctaga add new line

    ThreeTierMgt.BLOBImport(TempBlob,QRCodeFileName,FALSE);

    increasing SetResolutionValue reduces image,

    reduction SetResolutionValue increases the image

  12. Giancarlo Zavala says:

    The links to the sample objects and the required installation files are broken. I've been trying for a week, and can't get to the files.

    When I go to Customer Source links provided, I get a files not found 404 error.

    Is it possible to fix the links or upload them somewhere else where they can be downloaded?

    Thanks in advance.

  13. Very useful, but there is a codepage issue. It seems that the Microsoft.Dynamics.Nav.MX is not capable of handling special characters due to the employed original japanese codepage.

    If you use the function GetBarCode with a text containing special characters you get an error message:

    "Conversion error. Only JIS X 0201 is supported.".

    The default codepage for this code in international use is ISO 8859-1. Can the code be adjusted somewhere for this or is the japanese codepage fixed?

  14. Daniel Andersen says:

    Has anyone tried this in NAV 2013?

  15. Daniel Lee says:

    I'd tried this on NAV 2013 and it can work well in English. You may find Microsoft.Dynamics.Nav.MX.dll and use it without additional installation. The dll file is delivered with standard installation of RTC.

  16. _SIRO_ says:

    Hi all,

    I'm getting a problem using this .dll on NAV2013R2: we've converted the call for automation in call for DotNet type, but it doesn't work.

    Here the code:

       LOCAL PROCEDURE GetQRCode@1020038(QRCodeInput@1020001 : Text[1024]) QRCodeFileName : Text[1024];

       VAR

         IBarCodeProvider@1020000 : DotNet "'Microsoft.Dynamics.Nav.MX, Version=7.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.MX.BarcodeProviders.IBarcodeProvider";

       BEGIN

         GetBarCodeProvider(IBarCodeProvider);

         QRCodeFileName := IBarCodeProvider.GetBarcode(QRCodeInput);

       END;

       PROCEDURE GetBarCodeProvider@1020001(VAR IBarCodeProvider@1020000 : DotNet "'Microsoft.Dynamics.Nav.MX, Version=7.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.MX.BarcodeProviders.IBarcodeProvider");

       VAR

         QRCodeProvider@1020002 : DotNet "'Microsoft.Dynamics.Nav.MX, Version=7.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.MX.BarcodeProviders.QRCodeProvider";

       BEGIN

         //IF ISCLEAR(QRCodeProvider) THEN

         //  CREATE(QRCodeProvider,TRUE,TRUE);

         QRCodeProvider := QRCodeProvider.QRCodeProvider;

         IBarCodeProvider := QRCodeProvider;

       END;

    Here the error:

    Microsoft Dynamics NAV


    Cannot create an instance of the following .NET Framework object: assembly Microsoft.Dynamics.Nav.MX, Version=7.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, type Microsoft.Dynamics.Nav.MX.BarcodeProviders.QRCodeProvider.


    OK


    The error happens to this line:

    QRCodeProvider := QRCodeProvider.QRCodeProvider;

    If we use this .dll from Visual Studio it works.

    Could anybody help me?

    Thank you very much!

  17. _SIRO_ says:

    Solved!

    All DotNet variable must run to the same side (RUNONCLIENT = Yes)

  18. Peter Versteege says:

    How can I define the size of the QR-code, that is the number of modules of the QR-code ? As far as I understand the function ResizeBMP is something else, or not ?

    I need to have a QR-code, 41 x 41, Level L. Is it possible to adjust this setting by using this update ?

  19. Gerardo Rentería says:

    Somebody can help me, I try to use this DLL in a NAV 2009 R2.

    I install the msi file, but when I try to use in NAV, it shows only three functions.

    Microsoft.Dynamics.NAV.MX.HashAlgorithmType

    Microsoft.Dynamics.NAV.MX.ISignatureProvider

    Microsoft.Dynamics.NAV.MX.SignatureProvider

    I try to use  Microsoft.Dynamics.NAV.MX.dll file like a add-in from NAV 2013 o NAV 2013 R2 but an error appear, because the version is superior.

    Thanks in advanced.

  20. Gustaf Normand says:

    Hi all

    The generated QR Code is a little too big in my reports.

    Every little square (I believe they are called modules) in the code is 3×3 pixels.

    Is there any way to pass parameters the the IBarCodeProvider class to change to perhaps 2×2 pixel modules?

    Is there any documentation available for that class?

    Thank you!

  21. Sateesh says:

    I've installed MicrosoftDynamicsNav50SP1MXSignatureProvider in my local computer, but I cannot see  QRCodeProvider  and IBarCodeProvider classes

    I'm expecting 'Microsoft Dynamics Nav MX Services'.IBarCodeProvider" should be there in my Automation list. Please advise

  22. ali says:

    hi

    I used the code below to build QrCode, with Refrence QRCoder.dll

    English was displayed without problems

    But

    Persian text when I was just the first two letters of the word Profile

    Code:

    protected void btnGenerate_Click(object sender, EventArgs e)

    {

    string code = txtCode.Text;

    QRCodeGenerator qrGenerator = new QRCodeGenerator();

    QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code,QRCodeGenerator.ECCLevel.Q);

    System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();

    imgBarCode.Height = 150;

    imgBarCode.Width = 150;

    using (Bitmap bitMap = qrCode.GetGraphic(20))

     {

       using (MemoryStream ms = new MemoryStream())

       {

         bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

         byte[] byteImage = ms.ToArray();

         imgBarCode.ImageUrl = "data:image/png;base64," +  Convert.ToBase64String(byteImage);

        }

          plBarCode.Controls.Add(imgBarCode);

      }

    }

    Please help me

    Wait answered؟

    Grateful

  23. Evelien Wieringa says:

    Does anyone have the MXElectronicInvoice.msi file described in this posting?

    I would be most gratefull. I have to create a QR barcode in NAV2013.

    I have downloaded the Mexican NAV version but it was not included.

    The link in this posting is not valid anymore.

  24. Mikhail says:

    @Evelien Wieringa

    Here are the updated links:

    mbs.microsoft.com/…/MSDNAV2009SP1ElecInvoice

    mbs.microsoft.com/…/MSDNAV5SP1ElecInvoice

    Kai Kowalewski on previous page was kind enough to provide them. You have to be logged in to CustomerSource to download.

  25. Rita says:

    Hello everyone!!!

    Does anybody tried this in NAV 2015?

  26. Lombie says:

    Hi I have downloaded this file and it does not include the file MXElectronicInvoice.msi. Instead it is called MicrosoftDynamicsNav2009SP1MXSignatureProvider.msi. When I install it the automation object is not visible in NAV 2009R2 the object visible is "Dynamics NAV MX Signature Provider". How do I get the correct DLL so I can test this functionality?

    Thanks in advance.

    1. Jpatwl says:

      Hi
      I am having same issue which one of the user is having with NAV 2009 R2.

      I have downloaded this file and it does not include the file MXElectronicInvoice.msi. Instead it is called MicrosoftDynamicsNav2009SP1MXSignatureProvider.msi. When I install it the automation object is not visible in NAV 2009R2 the object visible is “Dynamics NAV MX Signature Provider”. How do I get the correct DLL so I can test this functionality?

      Can any one please help where to get MXElectronicInvoice.msi. for NAV 2009 R2?

      Thank you.

  27. Tadej says:

    "Hello everyone!!!

    Does anybody tried this in NAV 2015?"

    Working well

  28. Sachin Zade says:

    Hello everyone!!!

    Does anybody have solution of QR Code in NAV 2015W1?”

    Regards,
    Sachin Zade
    Pune
    9130559753

  29. Simone F. says:

    Hi,
    I’d like to implement QR codes in my RTC reports (NAV 2009R2).
    I read that someone succeeds, but many peoples have my difficulties…

    I have downloaded MicrosoftDynamicsNav2009SP1MXSignatureProvider.msi
    I have imported Codeunit 50010 QR Code Management hoping to go in my NAV 2009R2.

    Unfortunately some variables like IBarCodeProvider don’t find related addin ‘Microsoft.Dynamics.Nav.MX, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’.Microsoft.Dynamics.Nav.MX.BarcodeProviders.IBarcodeProvider

    The only similar assembly in the list is MicrosoftDynamics.Nav.MX (without the point) version 1.0.0.0, coherent with version of the installed dll MicrosoftDynamics.Nav.MX.dll

    Selecting “MicrosoftDynamics.Nav.MX” available types are only:
    -Microsoft.Dynamics.NAV.MX.HashAlgorithmType
    -Microsoft.Dynamics.NAV.MX.ISignatureProvider
    -Microsoft.Dynamics.NAV.MX.SignatureProvider
    Where can I find requested BarcodeProvider ?

    Where am I wrong?
    Any help will be appreciated!
    Thanks