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, ...
Suggested Answer

Getting error Field 'Product' must be filled in. Field 'Item number' must be filled in

(3) ShareShare
ReportReport
Posted on by 275
Hello,
On a custom Inquiry form, that shows details related to item id and product name etc.., i added a new logic to retrieve item name, vendor name and sales price, after that i keep on getting error message when opening the form saying "Field 'Product' must be filled in. Field 'Item number' must be filled in." After i commented the research() and refresh() in my code, the error message didnt show anymore when opening the form, but when i try to filter, it didnt allow me and shows this error. this form is a custom ISV FORM, thats why the code is on the activated event handler because i had to extend. so please if anyone can help me resolve it.
 
here is my code:
-------------------
 [FormDataSourceEventHandler(formDataSourceStr(DPPdsInventBatchShelfLifeByWHS, InventBatch), FormDataSourceEventType::Activated)]
        public static void InventBatch_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
        {
        
        
        FormRun formRun = sender.formRun();
        if (formRun)
        {
            FormDataSource inventBatchDS = formRun.dataSource(formDataSourceStr(DPPdsInventBatchShelfLifeByWHS, InventBatch));
            if (inventBatchDS)
            {
               // inventBatchDS.executeQuery();
                InventBatch inventBatchRec = inventBatchDS.getFirst();
                while (inventBatchRec)
                {
                   
                    if (inventBatchRec.SearchName == "" || inventBatchRec.SearchName == null && inventBatchRec.VendName == "" || inventBatchRec.VendName == null)
                    {
                        InventTable inventTableRec;
                    
                        select firstonly NameAlias, PrimaryVendorId from inventTableRec
                        where inventTableRec.ItemId == inventBatchRec.ItemId;
                        if (inventTableRec && inventTableRec.NameAlias != "")
                        {
                            inventBatchRec.SearchName = inventTableRec.NameAlias;
                        }                       
                        if (inventTableRec && inventTableRec.PrimaryVendorId != "")
                        {
                            inventBatchRec.VendName = inventTableRec.PrimaryVendorId;
                        }
                      }
                    if (inventBatchRec.Amount == 0.0) 
                    {
                        PriceDiscTable priceDiscRec;
                        InventTable inventTableRec;
                        select firstonly Amount from priceDiscRec
                            where priceDiscRec.ItemCode == PriceDiscProductCodeType::Table
                            && priceDiscRec.ItemRelation == inventBatchRec.ItemId;
                        if (priceDiscRec && priceDiscRec.Amount != 0.0)
                        {
                            inventBatchRec.Amount = priceDiscRec.Amount;
                        }
                    }

                    inventBatchRec = inventBatchDS.getNext();
                }
              // inventBatchDS.refresh();
               // inventBatchDS.research();
            }
        }
    }
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at
    First of all, let me simplify your code and make it easier to read:
     
    [FormDataSourceEventHandler(formDataSourceStr(DPPdsInventBatchShelfLifeByWHS, InventBatch), FormDataSourceEventType::Activated)]
    public static void InventBatch_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormDataSource inventBatchDS = sender;
    
        InventBatch inventBatchRec = inventBatchDS.getFirst();
        
        while (inventBatchRec)
        {
            if (inventBatchRec.SearchName == "" || inventBatchRec.SearchName == null && inventBatchRec.VendName == "" || inventBatchRec.VendName == null)
            {
                InventTable inventTableRec;
            
                select firstonly NameAlias, PrimaryVendorId from inventTableRec
                    where inventTableRec.ItemId == inventBatchRec.ItemId;
                    
                if (inventTableRec && inventTableRec.NameAlias != "")
                {
                    inventBatchRec.SearchName = inventTableRec.NameAlias;
                }                       
                if (inventTableRec && inventTableRec.PrimaryVendorId != "")
                {
                    inventBatchRec.VendName = inventTableRec.PrimaryVendorId;
                }
              }
            if (inventBatchRec.Amount == 0.0) 
            {
                PriceDiscTable priceDiscRec;
                InventTable inventTableRec;
                
                select firstonly Amount from priceDiscRec
                    where priceDiscRec.ItemCode == PriceDiscProductCodeType::Table
                    && priceDiscRec.ItemRelation == inventBatchRec.ItemId;
                    
                if (priceDiscRec && priceDiscRec.Amount != 0.0)
                {
                    inventBatchRec.Amount = priceDiscRec.Amount;
                }
            }
    
            inventBatchRec = inventBatchDS.getNext();
        }
    }
    The whole idea is wrong. You're trying to iterate records loaded to the data source, but no loading happened. You're running your code during form initializing, before actually running the form and loading the data.
     
    And there are many other issues.
     
    For example, you're changing the value of a local variable, which won't have any effect on the form.
     
    There is no point comparing string values with null (e.g. inventBatchRec.SearchName == null), because strings in X++ can't be null.
     
    Your logic for selecting PriceDiscTable makes no sense to me. There may be many records for the given item and you just take a random one, regardless of what kind of price it is, whether it hasn't expired and so on. You'll need think about what you want to achieve before designing this logic.
     
    If you want to get InventTable.Name and InventTable.PrimaryVendorId related to InventBatch, you should use a join. Add a data source for InventTable and join it with InventBatch data source (if such an InventTable data source doesn't already exist, of course) and display the InventTable fields in the form.
     
  • ISDev Profile Picture
    275 on at
    Hi martin,
    I appreciate your feedback! My main goal is to ensure that the error message doesn't show up again and that my request is implemented correctly. If my current approach is incorrect, I need your help in fixing the code accordingly to achieve the desired functionality. Please modify it as needed to make it work properly. Thanks!
  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at
    I already gave you my suggestion regarding InventTable - read the last paragraph.
     
    I can't give you code "to achieve the desired functionality" regarding PriceDiscTable, because you didn't tell us what the desired functionality is. I suspect you don't know it either, therefore you're aren't yet in a position to start designing a solution. You need to learn a bit about how pricing works (e.g. that some prices may be inactive, there may be multiple active one, you need to take AccountRelation or currency into account...), discuss with users what they want to achieve and desing a functional solution. When you know how the business logic should look like, we can start talking about code.
  • ISDev Profile Picture
    275 on at
    I need to retreive values from released product details form  of the product name to my custom form, as well as vendor from  released product details form
     
    Moreover the i need to get the value of field "price".  from released product Ã¨ Sell TAB Ã¨ Sales Price Ã¨ take the sales price EX. 2370.00
  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at
    All right, you know you want the Price field, but you don't know from which record, do you? There may be dozens of even hunders of records in PriceDiscTable for a given ItemId.
  • ISDev Profile Picture
    275 on at
    Exactly. how i can resolve my issue in this case?
  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at
    I already answered that: You need to learn a bit about how pricing works (e.g. that some prices may be inactive, there may be multiple active one, you need to take AccountRelation or currency into account...), discuss with users what they want to achieve and desing a functional solution. When you know how the business logic should look like, we can start talking about code.
     
    You can't write code if you have no idea about what it should do.
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    When you say an inquiry form, you should ideally have a View or a query underlying it. As this is ISV, were you able to extend that View or Query to add additional datasources? If yes, you can simply add the InventTable and a computed method for Pricing.
     
    If you are not able to proceed this way, I would suggest to talk to the ISV team and achieve this. Otherwise, looping through all the records for each line and updating current record will create unneccessary performance issues.
     
    Else, if you are ok with not filterable fields, you can do a display method as the ISV is not allowing further.
  • ISDev Profile Picture
    275 on at
    Hi,
    HERE ARE THE FORM AND ITS DATASOURCES PROPERTIES
     
  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    Can you please confirm if you can add a new datasource with a join?

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans