Adding Images to items.

Hi,
Many of you people, might have came across a requirement where you need to add images to items.
Regarding the same, we have a standard functionality In AX 2009 to add an company logo to every company.

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.
Open the Application Object Tree (AOT) and browse to Menu Items>Display>CompanyImage.
Open another AOT window and browse to your Customers form (Forms>CustTable).
Open the Design>Design>ButtonGroup node of the CustTable form.
Drag the CompanyImage menu item in the ButtonGroup.
Right-click the just added MenuItemButton and choose Properties. Add Customer Logo as Text property.
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;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s