Image in data provider class AX 2012 R2

Hi all,

I’m creating an SSRS report in AX 2012 R2. One of the requirement is to display an image in the report.

I’m trying to use Image class in the data provider class, so I wrote something like this:

Image image;

image = new Image();

When I preview the report in visual studio, I always getting an error. But when I erase the image code, I can preview my report without getting any error.

My question is how to load an image in data provider class? Can’t I use Image class in the data provider? and why am I always getting an error when using Image class in the data provider class?

Thank you in advance,

Esther

Hi Esther,

I would suggest taking a look at the SalesInvoiceDP and SalesInvoiceDPBase classes and the salesInvoice SSRS report. This is a monster report that is very complex so normally its the best place to pickup code tips for use as it normally contains everything!

You will notice there is a field on the header temp table CompanyLogo this is the company image and its logic is in both classes. I think the logic you want is in \Classes\SalesInvoiceDPBase\init

Its worth noting that AX normally handles images as containers, how are you assigning the value in your temp table? If you are still getting problems post the error and the code I will have a look for you.

Thanks

-Howard Webb

Hi Howard,

Thank you for the reply,

I’ve looked at the sales invoice report. The SalesInvocieDP load the image from the database and display it in the report. What I need to achieve is to load an image from a physical file and display it in the report. So I need to use Image class in the data provider.

I try putting this code in the data provider class:

Image image = new Image();

But when I preview the report in visual studio, I always getting an error without any explanation. When I erase that line of code and preview the report, the report works perfectly.

Do you have any idea why instantiating an Image class in data provider would cause an exception in the report?

Thank you,

Esther Mulijono

HI Esther ,

In your TmpTable drag & drop the EDT bitmap , and go to your RDP class insert the Image in that bitmap field , If U want to insert the company image then there is a Table in AOT call CompanyImage .

Thanks

Sumit

Hi Sumit,

What I want to achieve is slightly different, I need to load an image from physical file, not from a database. Loading an image from database, like the company image works fine,

Thank you,

Esther

HI Esther,

If u want to directly import the image then go to Visual studio add image and right click on that image then import your image from your PC .

Before importing you have to specify the type of your image .png or any … below the import option .

Thanks

sumit

Hi Ester,

I found below code on CompanyImage form

void clicked()

{

FilenameFilter filter = [‘Image Files’,’.bmp;.jpg;.gif;.jpeg’];

BinData binData = new BinData();

str extention, path, nameOfFile;

super();

imageFilePathName = WinAPI::getOpenFileName(element.hWnd(),filter,’’, “@SYS53008”, ‘’,’’);

if (imageFilePathname && WinAPI::fileExists(imageFilePathName))

{

[path, nameOfFile, extention] = fileNameSplit(imageFilePathName);

if (extention == ‘.bmp’ ||

extention == ‘.jpg’ ||

extention == ‘.gif’ ||

extention == ‘.jpeg’)

{

binData.loadFile(imageFilePathName);

imageContainer = binData.getData();

element.showLogo();

element.insert();

}

else

{

throw error("@SYS89176");

}

}

}

Hope this will help you… you can fetch image from source path and convert it in container using BinData class and then that container we can use in temp table