web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Display Product Image In Custom Form Grid

(0) ShareShare
ReportReport
Posted on by 5

Good day,

I am attempting to create a custom form to display the ItemId from the InventTable and the relevant item's image from the EcoResProductImage table in grid format using a Window control for the image.

On the form methods I have the following code:

public void showImage()
{
    Image   itemImage;
    ;
        productImageRecId = InventTable::find(InventTable.ItemID).RecId;

        if(productImageRecId)
        {
            select ecoResProductImage where ecoResProductImage.RefRecId == productImageRecId
            || ecoResProductImage.RefRecord == productImageRecId;

            containerImage =  ecoResProductImage.ThumbnailSize;

            itemImage = new Image();
            itemImage.setData(containerImage);
            Image.image(itemImage);
            image.widthValue(itemImage.width());
            image.heightValue(itemImage.height());
        }
}

and in the form data source I have the InventTable with an Active method with the following code:

public int active()
{
    int ret;

    ret = super();

    element.showImage();

    return ret;
}

This does produce a form that displays the item and image but only when I select each individual line. I know this is because of the active method, and I know that I would need to rather create a display method on the form data source so that it displays all images when the form opens. What I am unsure about is what to select and what to return in the display method. I can use the same select statement I used in the showImage() method but I do not know what to return then.

I have attempted to use the CompanyImage form and its code as reference but I have been unsuccessful. 

I am fairly new to AX dev and dev in general so any guidance would be much appreciated.

Thank you in advance.

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi Justin,

    please check this documentation for instructions: docs.microsoft.com/.../images-form-grid

  • Ecalin Profile Picture
    5 on at

    Hi Nikolaos,

    Thank you for the very swift reply, and for the documentation.

    I am assuming I would need to look at the Image type: Binary Image and the return type of Container ?

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Yes, that's correct.

  • Suggested answer
    Ecalin Profile Picture
    5 on at

    Thank you Nikolaos,

    This has helped.

  • Ecalin Profile Picture
    5 on at

    Hi Nikolaos,

    I am terribly sorry but I am still having difficulty with the display method. I believe it is probably something small I am missing somewhere.

    Here is the code for the display method

    public display container DisplayItemImage()
    {
        container   imageContainer;
    
        productImageRecId = InventTable::find(InventTable.ItemId).RecId;
    
        if (productImageRecId)
        {
    
            select EcoResProductImage
            where ecoResProductImage.RefRecId   == productImageRecId
                || ecoResProductImage.RefRecord == productImageRecId;
    
            imageContainer =  ecoResProductImage.ThumbnailSize;
        }
    
        return imageContainer;
    }

    This compiles fine and I have added this data method and data source to my Window control on the form, but when I run the form the client crashes

    Is there any additional advice or guidance you can provide ?

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    1. If the display method is in your form data source, you need to add one parameter in the method, corresponding with the form data source table. For example if it's in InventTable data source, you need to add parameter "InventTable _inventTable" to the method. This way it's always executed for the current record.

    2. Since you already have InventTable record at hand, there's no need to fetch it again from the database (line 5)

    3) I'm not so familiar with the product image data model, and the table relations don't help me understand it, but I assume that RefRecord points to EcoResProduct table, not InventTable. 

    So you would need to search for:

    select firstonly ecoResProductImage where ecoResProductImage.RefRecord == _inventTable.Product;

    4. In your code, make sure that you found an EcoResProductImage record before trying to use it.

  • Ecalin Profile Picture
    5 on at

    Hi Nikolaos,

    Again thank you for the very swift reply.

    I have made some changes to my code based on your recommendations.

    public display container DisplayItemImage(InventTable  _inventTable)
    {
        container   imageContainer;
    
            select firstonly EcoResProductImage
            where ecoResProductImage.RefRecord == _inventTable.Product;
    
            imageContainer =  ecoResProductImage.ThumbnailSize;
    
            return imageContainer;
    }

    Is the declaration of the imageContainer variable on line 8 and the return on line 10 correct ?

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi Justin,

    on line 6, please use the _inventTable variable instead of inventTable. This way it uses the record of the current grid row.

    About lines 8 and 10, just test it - does it work?

  • Ecalin Profile Picture
    5 on at

    Hi Nikolaos,

    Unfortunately not no. The client still crashes when opening the form.

    I have added an executeQuery method to filter on just 1 item that I know contains an image to test, but it still crashes.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans