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

to filter the records in grid based on the field value in header

(2) ShareShare
ReportReport
Posted on by 1,836
hi 
everyone,
I was trying to filter the records in line based on the field value in header , but i am not getting the desired  output , please anyone help me on this .
my code is below . 
 
 
i have debugged the code not getting the record , please suggest hoe can i get the header record .
 
thanks ,
Regards,
Dinesh
I have the same question (0)
  • Dineshkarlekar Profile Picture
    1,836 on at
    i have written the code on init method of form 
     public void init()
        {
         
            if (element.args().record() as DTDMCHeader )
            {
                if (element.args().record().TableId == tablenum(DTDMCHeader))
                {
    
                    locationId  = DTDMCHeaderLines::findRecId(element.args().record().RecId).inventLocationId;
                }
            }
            super();
        }
    and below code is written on form datasource method , can anyone suggest me where i am getting wrong , i am not getting records in debugger.
     
         public void init()
            {
              
                super();
                abcQueryRange = this.query().dataSourceName('DTDMCHeaderLines').addRange(fieldnum(DTDMCHeaderLines, inventLocationId));
    
            }
    
            /// <summary>
            ///
            /// </summary>
            public void executeQuery()
            {
    
                if (locationId)
                {
                    abcQueryRange.value(queryValue(locationId));
                }
                super();
            }
    thanks,
    Regards,
    Dinesh
  • Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi Dinesh,

    What header record you are not getting? which line of code are you referring to? as I don't understand.
    Do you mean LocationId is empty or what?

    Also can you please take a screenshot of the form, showing the header field and grid?
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi ,
    Thanks for reply ,
    Location id is empty .i am not getting value in 
    element.args().record()
  • Dineshkarlekar Profile Picture
    1,836 on at
    when i open the from for specific header record it should show the record only with warehouse in header ,now i am getting all the warehouse in lines , an in debugger i am getting the null values .
  • Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi Dinesh,

    What is LocationId? is it a defined variable or an existing field on the form?

    ​​​​​​​Just to understand if you are trying to set the LocationId field when the form is first open from the lines?

    if it was an actual field, why do u need element.args().record() in the first place? why not fill LocationId directly? isn't DTDMCHeader the first datasource in the form?


    Also check this link in general
    https://daxingwitheshant.blogspot.com/2019/04/how-to-filter-grid-based-on-control.html
  • Dineshkarlekar Profile Picture
    1,836 on at
    Location id is  warehouse in header , the data is get into the form unsing insert method i so i want to filter the lines tab using location ie warehouse which are common but i cant use join here , so i have removed joined form data source from lines so all the lines are getting displayed . yes dmc header is first datasource in form , but still i am getting null values i am unable to upply filter on form can you help me on this please .
  • Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi Dinesh,

    So if LocationId is the warehouse in the header and it's value is already filled, why are you then overriding it with this line of code?
    locationId  = DTDMCHeaderLines::findRecId(element.args().record().RecId).inventLocationId;

    So to make sure i understood your requirement correctly.

    When you first open the form, you want the lines to be filtered based on the header field. where the header field is already filled...right?
  • Dineshkarlekar Profile Picture
    1,836 on at
    yes you are right , how can i get this done then ,can you please guide me on this 
  • Suggested answer
    Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi Dinesh,

    Did you check the link i sent you in previous replies. it should solve your issue. https://daxingwitheshant.blogspot.com/2019/04/how-to-filter-grid-based-on-control.html
     
    just put your code on the form datasource of the line table

    [ExtensionOf(formDataSourceStr(YourForm,YourLinesTable))]
    final class YourClass_Extension
    {
        public void executeQuery()
        {
            next executeQuery();

            this.query().dataSourceTable(tableNum(YourLinesTable)).addRange(fieldNum(YourLinesTable, LocationId)).value(SysQuery::value(headerTable.LocationId));
        }
    }
     
    and as the blog showed, if the header can be modified then you need to add code there as well

    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
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    Can you show us your form design? Because you are saying you need to filter lines record based on header warehouse ID. In that case you can simply put a relation between header and line. But why do you require some custom code to do this? Can you give us your full business requirement?

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 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans