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

Notifications

Announcements

Community site session details

Community site session details

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

Error opening EcoResProductDetailsExtended form in F&O

(1) ShareShare
ReportReport
Posted on by 17
"Assignment 6
Objective: Develop and extend features to enhance the management of released products including tracking product reviews
Extend InventTable and form:
Add new field for rating which you created earlier and display the rating as * on the invent table form
Get the Rating from ProductReviewForm (max value rating for the form)"
 
This was the task given and in accordance to the requirement about management of released products I selected the EcoResProductDetailsExtended form and created an extension. I extended the InventTable which is a data source in the form and added custom fields ReviewRating (base enum containing 1-5 rating values) and RatingStar (EDT container) and built the solution after which the fields reflected in the form extension data source and I added ReviewRating to the forms design node and since I can't drag drop a container, I created an image control and bound it to the container by data source and field properties and I also created resources to store images of the star ratings. Created a code extension and wrote this as the code: 
 
[ExtensionOf(formStr(EcoResProductDetailsExtended))]
final class EcoResProductDetailsExtended_YD_Extension
{
    public void init()
    {
        next init();
        
        ProductReview productReview;
        FormDataSource inventTableDS = this.datasource(formDataSourceStr(EcoResProductDetailsExtended, InventTable));
        if (inventTableDS && inventTableDS.cursor())
        {
            // Fetch the highest rating for the current product
            select firstOnly maxof(ReviewRating) from productReview
                where productReview.ProductId == inventTableDS.cursor().(fieldNum(InventTable, ItemId));
            if (productReview)
            {
                str imagePath;
                BinData binData = new BinData();
                container imageContainer;
            
                // Determine the image path based on the rating
                switch (productReview.ReviewRating)
                {
                    case 1:
                        imagePath = resourceStr("Stars_1");
                        break;
                    case 2:
                        imagePath = resourceStr("Stars_2");
                        break;
                    case 3:
                        imagePath = resourceStr("Stars_3");
                        break;
                    case 4:
                        imagePath = resourceStr("Stars_4");
                        break;
                    case 5:
                        imagePath = resourceStr("Stars_5");
                        break;
                    default:
                        imagePath = resourceStr("NoStarRating");
                        break;
                }
                // Load the image into BinData
                binData.loadFile(imagePath);
                // Convert binary data into a container
                imageContainer = binData.getData();
                // Update the RatingStar field with the image container
                inventTableDS.cursor().(fieldNum(InventTable, RatingStar)) = imageContainer;
                // Refresh the data source to display the image
                inventTableDS.refresh();
            }
        }
    }
}"
 
The code isn't showing any errors in the compiler but when I build the solution I get this error:
"SeverityCodeDescriptionProjectFileLineSuppression State
ErrorOperationCanceledException: The operation was canceled.ProductManagement (ISV) [YD]C:\Program Files (x86)\MSBuild\Microsoft\Dynamics\AX\Microsoft.Dynamics.Framework.Tools.BuildTasks.17.0.targets63"
 
And when I try to separately open the form in F&O it wont let me open it and gives this as an error
"Object reference not set to an instance of an object.
The form with name ecoresproductdetailsextended could not be opened."
IMG_9648.jpeg
IMG_9647.jpeg
I have the same question (0)
  • Layan Jwei Profile Picture
    8,133 Super User 2025 Season 2 on at
    Hi,
     
    Did you debug and see where it fails exactly?
    I think it's failing at this line:
    inventTableDS.cursor().(fieldNum(InventTable, ItemId));
     
    Maybe try this instead:
     
    InventTable inventTableLocal = inventTableDS.cursor();​​​​​​
    select firstOnly maxof(ReviewRating) from productReview where productReview.ProductId == inventTableLocal.ItemId;
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
    ​​​​​​
  • Suggested answer
    Martin Dráb Profile Picture
    238,149 Most Valuable Professional on at
    The logic of your code is wrong. You're trying to access the current InventTable record, but there isn't any, because your code runs when the form is still being initialized, before any data source records get loaded.
     
    You should create a display method instead of your current code and the container field.
     
    Also, you should also familiarize yourself with the debugger. In this case, you'd know where exactly the error was thrown, which could help you to understand the problem. When you get an error that you don't understand, your next step should always be getting more information.
  • YD-01011239-0 Profile Picture
    17 on at
    @Martin Dráb i'll give your suggestions a try and get back to you!
  • YD-01011239-0 Profile Picture
    17 on at
    @Layan Jwei thanks for the code correction i'll give it a try and get back to you!
  • YD-01011239-0 Profile Picture
    17 on at
    @Martin Dráb @Layan Jwei i took your respective suggestions and made changes to the code and ran the debugger  
     
    [ExtensionOf(formStr(EcoResProductDetailsExtended))]
    final class EcoResProductDetailsExtended_YD_Extension
    {
        // Create a display method for the RatingStar field
        public display container displayRatingStar()
        {
            ProductReview productReview;
            container imageContainer;
            InventTable inventTable = this.datasource(formDataSourceStr(EcoResProductDetailsExtended, InventTable)).cursor();
            
            if (inventTable)
            {
                // Get the highest rating for current product
                select firstOnly maxof(ReviewRating) from productReview
                    where productReview.ProductId == inventTable.ItemId;
                    
                if (productReview)
                {
                    str imagePath;
                    BinData binData = new BinData();
                    
                    // Your existing switch case for image paths
                    switch (productReview.ReviewRating)
                    {
                        case 1:
                            imagePath = resourceStr("Stars_1");
                            break;
                        case 2:
                            imagePath = resourceStr("Stars_2");
                            break;
                        case 3:
                            imagePath = resourceStr("Stars_3");
                            break;
                        case 4:
                            imagePath = resourceStr("Stars_4");
                            break;
                        case 5: 
                            imagePath = resourceStr("Stars_5");
                            break;
                        default:
                            imagePath = resourceStr("NoStarRating");
                            break;
                    }
                    
                    if (binData.loadFile(imagePath))
                    {
                        imageContainer = binData.getData();
                    }
                }
            }
            return imageContainer;
        }
    }
  • Layan Jwei Profile Picture
    8,133 Super User 2025 Season 2 on at
    Hi,
     
    I'm not sure if u took all suggestions into account.
     
    What is the code the calls the method "displayRatingStar" can you show us the full code?
     
    Also again can you please put break points and tell us at which line exactly does the code fail?
  • Verified answer
    Martin Dráb Profile Picture
    238,149 Most Valuable Professional on at
    Your display method is definetely wrong. It's defined on the form and it (in a over-complicated way) refers to the current buffer, but the display method should refer to the buffer it runs for, not the currently selected one. It should be defined either on the table (and refer to this variable) or a form data source (and use a method parameter). 
     
    First of all, learn how to create a trivial display method returning a fixed value. Later we can talk about what code to put there, but you need to learn the basics first.
     
    Note that you can find a plenty of information about display methods on the internet, as well as many examples in the standard codebase.

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

News and Announcements

Season of Giving Solutions is Here!

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
Abhilash Warrier Profile Picture

Abhilash Warrier 732 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 289 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans