Skip to main content

Notifications

Announcements

No record found.

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.

  • Ecalin Profile Picture
    Ecalin 5 on at
    RE: Display Product Image In Custom Form Grid

    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.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Display Product Image In Custom Form Grid

    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
    Ecalin 5 on at
    RE: Display Product Image In Custom Form Grid

    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
    nmaenpaa 101,156 on at
    RE: Display Product Image In Custom Form Grid

    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
    Ecalin 5 on at
    RE: Display Product Image In Custom Form Grid

    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
    Ecalin Profile Picture
    Ecalin 5 on at
    RE: Display Product Image In Custom Form Grid

    Thank you Nikolaos,

    This has helped.

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Display Product Image In Custom Form Grid

    Yes, that's correct.

  • Ecalin Profile Picture
    Ecalin 5 on at
    RE: Display Product Image In Custom Form Grid

    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
    nmaenpaa 101,156 on at
    RE: Display Product Image In Custom Form Grid

    Hi Justin,

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

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans