My 2p about ERP Solutions, Information Worker Solutions and other software products (mainly Microsoft Dynamics AX and Microsoft SharePoint).

15 September 2009

Storing images with Dynamics AX

by Patrik Luca 9 comments

Tag



Business Requirement: uploading image files for re-use

You want to implement functionality in Dynamics AX to store images (.jpg, .bmp, … files) which can be re-used for f.e. printing purposes on commercial documents such as the invoice or the packing slip. The end-user must be able to upload in an easy way such a file stored on his local disk, or to view and change the image.

Solution: re-use the Company logo code

Such functionality exists in standard Dynamics AX to store a Company logo for each Company Account (Basic>Setup>Company information>Company logo button). The great news is the code can be easily reused on whatever other form, since the table CompanyImage for storage of the images is generic as it contains the TableId and RecId of the record to which you link the image.

In the next example I’ll attach a logo to my CustTable records: so for each customer I would like to store a logo.

  1. Open the Application Object Tree (AOT) and browse to Menu Items>Display>CompanyImage.
  2. Open another AOT window and browse to your Customers form (Forms>CustTable).
  3. Open the Design>Design>ButtonGroup node of the CustTable form.
  4. Drag the CompanyImage menu item in the ButtonGroup.
  5. Right-click the just added MenuItemButton and choose Properties. Add Customer Logo as Text property.
  6. Save your changes.

When you open the Customers form now, a new button will be available Customer Logo. Click on it and you’ll be able to attach an image file to the active customer record. No further coding needed for storing, changing, viewing the image!

Your records will be saved in the CompanyImage table with as RefTableId the TableId (77) of the CustTable and the RefRecId of the Customer record selected upon attaching the image file.

To use these images in f.e. a report, add a Bitmap control to the report Design.

Add a display method for this added Bitmap control which looks for example as underneath (I work further on the example where I added images to my CustTable records). In my example I suppose there is a datasource for CustInvoiceJour.

display Bitmap  showCustomerLogo()

{

    CustTable       custTable = CustTable::find(
custInvoiceJour.InvoiceAccount);

    ;

    return CompanyImage::find(custTable.dataAreaId,
custTable.TableId, custTable.RecId).Image;

}

Comments 9 comments
ניהול תיקים said...

great tip, thanks!

Patrik Luca said...

You're welcome.

Yigal said...

We have a slightly different task involving images. We want to upload employees photos into AX. We tried to use a simple SQL script which replaced the BLOB in an existant record in CompanyImage. We used another utility to verify that the new photo was realy uploaded and it was OK. However, the new photo is not displayed (neither the old one).

Is there a known way to upload images in batch ?

Patrik Luca said...

Hi Yigal,

this example job should help you out. It supposes the image functionality is added to the CustTable as described in my post. The job runs in company account 'dmo'. You should adapt accordingly, but it should give you an idea how to achieve your requirement.

static void Job2(Args _args)
{
Image image = new Image();
str filename;
CustTable custTable;
CompanyImage companyImage;
;

filename = "C:\\Temp\\Image.JPG";

select custTable
where custTable.AccountNum == '1';

if (Image::canLoad(filename))
{
image.loadImage(filename);
companyImage.Image = image.getData();
companyImage.RefTableId = 77;
companyImage.RefRecId = custTable.RecId;
companyIMage.RefCompanyId = 'dmo';
companyImage.insert();
}
}

sayeed said...

Hi Patrik;

I found your artical very help fully; i tried to implement same concept for "InventTable". I had added the image to the Item details form in the Inventory management. But when i try to display the image by using the below method getting the error "unknown source of datamethod".

display Bitmap loadItemImage()
{

;
return companyImage::find(inventTable.dataAreaId,inventtable.TableId,inventtable.RecId).Image;
}

Please help me with the solution.

Thanks;

Patrik Luca said...

Hi Sayeed,

did you set the datasource property to InventTable on the control with which you want to display the image on your inventtable form?

sayeed said...

Hi Patrik,
I need to display the image in the Report; as mention in your artical above i had followed the same steps.

"To use these images in f.e. a report, add a Bitmap control to the report Design."

I had wrote below display menthod; to return the image from companyImage table.

display Bitmap loadItemImage()
{
;
return companyImage::find(inventTable.dataAreaId,inventtable.TableId,inventtable.RecId).Image;
}

when i assign this method to datamethod property of Bitmap control in the report; i am getting the error "unknown source of datamethod"

Can you please help me how i can display the image in the report which is stored in companyimage table; I tried all the always but no luck.

Require your help.
Thanks;

WP said...

Hi Patrik

Thanks for this article. I’ created a new table with one field and two entries “Header” and “Footer” where I can place the images for reports like purchaseorder, salesinvoice…

How can I display the images generally in those reports?

Thanks,
WP

Anonymous said...

Good one.

This is axapta ERP blog for Technical and functional fields and includes Microsoft Dynamics Axapta tutorials and Dynamics Axapta Coverage. This blog also contains x++ code help for Ax developer and solution of technical and functional daily issues. This blog is specific for Microsoft dynamics programming. Enterprise portal, SharePoint services, business connectors and Enterprise Resource Planning applications and sql database.It will help to get Microsoft Business Solutions.


axapta ERP blog

Patrik Luca, Ieper, BELGIUM
Feel free to use or spread all of the content on my blog. In return, linking back to my blog would be greatly appreciated. All my posts and articles are provided "AS IS" with no warranties.

Subscribe feeds via e-mail
Subscribe in your preferred RSS reader

Subscribe feeds rss Most Read Entries

Subscribe feeds rss Recent Entries

Categories

Recommended Books


Subscribe feeds rss Recent Comments

This Blog is part of the U Comment I Follow movement in blogosphere. Means the comment field of this blog is made DOFOLLOW. Spam wont be tolerated.

Live Traffic Feed

Recent Visitors

Blog Archive

My Blog List

Followers

Guest Links