Thursday, March 25, 2021

X++ code to print QR code and Barcode on Report in AX

  • QR code on a report in AX 2009.

Image


In order to do this,

1.Create a new display method on the report. The below code can be used to generate QR code.

display container  qrcode()

{
    Bindata                 bindata = new Bindata();
    Image                   Imgobj;
    System.Drawing.Image    img;
    System.Drawing.Bitmap   obj;
    Filepath                sourcePath;
    container               con;
    InteropPermission interopPerm;
    FileIoPermission _perm;
    Microsoft.Dynamics.QRCode.Encoder encoder;
    System.Exception               ex;
    Set permissionSet;
;
    sourcePath = @"C:\temp\newQRCode.bmp";
    permissionSet = new Set(Types::Class);
    permissionSet.add(new FileIOPermission(sourcePath,'rw'));
    permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
    CodeAccessPermission::assertMultiple(permissionSet);

    encoder   = new Microsoft.Dynamics.QRCode.Encoder();
    obj = new System.Drawing.Bitmap(encoder.Encode("SYED IRFAN QR CODE TEST"));

    obj.Save(sourcePath,System.Drawing.Imaging.ImageFormat::get_Bmp());
    bindata.loadFile(sourcePath);
    con = bindata.getData();
    return con;
}

2.Add the image control on the report based on the display method. 



3.QR code can be seen on the report on running it.





  • Barcode  on a report in AX 2009.




1.Create a new display method on the report. The below code can be used to generate Barcode .


display BarCodeString barCode()
{
    Barcode barcode;
    ;
 
    barcode = Barcode::construct(BarcodeType::Code39);
    barcode.string(true, "SYED IRFAN BARCODE TEST");
    barcode.encode();
 
    return barcode.barcodeStr();
}

2. Set font properties  on the Barcode string control.

                                                                

3.Run the report and send the output to the screen.











1 comment:

  1. hello, i am getting this error on Ax2009 Object 'CLRObject' could not be created
    any resolution for that?

    ReplyDelete

Sending Email using X++ Code in D365 F&O/ AX 7 in HTML fomat

  I was just researching on the emailing capabilities in D365 and found that SysINetMail, SysMailer and some of the smmOutlook classes are d...