Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Filter records in child form based on Parent form

Posted on by 2,420

Good Morning,

I have one parent form and records are like the below

SalesAgreement id         Desc             ( 1st Form - FirstTable)

SA - 001                          Test

 

Jobid                              salesAgreemntid    (2nd Form  - secondTable)

JO-001                          SA - 001

JO-002                          SA - 001

Jobid                              SalesAgreementId                  TransDate       No of units      ( ThirdTable - Lines)

JO -001                          SA - 001                                   26/11/2019     1

JO -001                          SA - 001                                   26/11/2019     2

JO -002                          SA - 001                                   26/11/2019     3

JO -002                          SA - 001                                   26/11/2019     1

The above table is which do not have any relation with second table

So, now on Second Form i have 1 Menu Item Button to open Third table mean Third Form

Now i have to have multi selection in Second form.

Example : If is select Both Jobs and when i click Thirdform MI on Second form I must see all 4 records which are in 3rd table

What things i tried but its not working

1. In form - Init() - 

Formdatasource   fds ; (Global Dec)

in init()    (Did Concatenation but not woring in query ranges)

fds = element.args().record().Datasource();

JobTable        jobjtableDS;
str                  getjobid;
for(jobjtableDS= fds.getFirst(true) ? fds.getFirst(true) : fds.cursor(); jobjtableDS; jobjtableDS= fds.getNext())
{
getjobid += jobjtableDS.jobid+',' ;
}

if (getjobid)
{
getjobid = subStr(getjobid,1,strLen(getjobid)-1);
}

I sended as 

JobLine_ds.query().dataSourceTable(tableNum(JobProjLine)).addRange(fieldNum(jobProjLine, Jobid)).value(getjobid);

Test 2 

Added the same range in ExecuteQuery()

Not working.

Please help me in how can i pass selected records from form how to filter based on multiple values in one range.

Regards,

Have a nice day.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Filter records in child form based on Parent form

    No, I can't since I don't have your tables and forms. I can't test your code since I don't have it! Did you try my suggestion? We know how the system works and how to implement this kind of solution, and we have told you how to do it. 

    Next, you need to share more information with us since we don't know anything about your system and code, except what you share with us. For example, you could share screenshots where we see what was selected on the first form and what you see on the second form. As well as all code in your second form. Please help us help you, that's the best way for you to get good advice. Thanks!

  • AX 2012 r3 Profile Picture
    AX 2012 r3 2,420 on at
    RE: Filter records in child form based on Parent form

    Hi Nikaloas,

    There is no relaltion between these 2 tables.

    Nikaloas can you please try in your machine once.

    Regards

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Filter records in child form based on Parent form

    If the ranges seem correct, but you get too few records, one explanation can be the dynalinks which AX initializes automatically if there are realations between tables. The impact is that the records are automatically filtered depending on the active record on the caller form's data source.

    So, you could try to add "yourFormDataSource.clearDynalinks()" in the init method of your form data source.

    However this is pure guessing, since we don't have enough information.

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Filter records in child form based on Parent form

    Please elaborate what you mean that it's looping twice. I don't believe that you've just found a bug in AX kernel, therefore the problem is more likely on your side. Either you're calling the loop twice, or you have wrong expectations about the data.

    Please tell us concretely what you did and where things went wrong. "tried to add range But it is always taking the last record" isn't very specific.

    If you put the code to executeQuery(), you would be adding the same ranges every time when the query executes (e.g. when you referesh the form), which is clearly not what you want.

    Please don't forget that AX comes with an X++ debugger, which will tell you what's going on in your code.

  • AX 2012 r3 Profile Picture
    AX 2012 r3 2,420 on at
    RE: Filter records in child form based on Parent form

    Hi Nikolaos,

    Thanks for reply,

    I did debug when i was debugging it looped twice but when form opened i saw 2 records that is the last record is only added to range i.e Job 2.

    Regards,

    Have a great day

  • AX 2012 r3 Profile Picture
    AX 2012 r3 2,420 on at
    RE: Filter records in child form based on Parent form

    Hi Martin ,

    Thanks for reply,

    I have tried with while loop just looping the formds.It loops twice and adds range

    and tried to add range But it is always taking the last record that is job 2 and i am getting only 2 records instead of 4.

    How can i print Qbds (to String)

    can you tell me where is right place either form init() or form Datasource ExecuteQuery()

    Regards,

    Have a greate day

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Filter records in child form based on Parent form

    By the way, I would simplify and improve your code in init() to this:

    MultiSelectionHelper selectionHelper = MultiSelectionHelper::construct();
    selectionHelper.parmDataSource(FormDataUtil::getFormDataSource(this.args().record());
    
    QueryBuildDataSource lineQbds = jobLine_ds.queryBuildDataSource();
    
    JobTable jobTable = selectionHelper.getFirst();
    while (jobTable)
    {
        lineQbds.addRange(fieldNum(JobProjLine, JobId)).value(queryValue(jobTable.JobId));
        jobTable = selectionHelper.getNext();
    }

    Also note that code is much easier to read if you paste it by using Insert > Insert Code (in the rich formatting view), as I did.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Filter records in child form based on Parent form

    You need to debug it, and see how each part of your code works.

    You clearly have many parts and you need to make them all working.

    1. Determining the selected records of the caller data source

    2. Gathering the job ids of the selected records to one string variable

    3. Removing the last comma from the string

    4. Setting the string as range in the query, for the JobId field

    Please let us know your findings of each phase. And if it doesn't work, please let us know what you mean by "its not working". As you might imagine, troubleshooting is easier if you know what the actual "trouble" is :)

    By the way, did you know that you can add multiple ranges (one for each job id) instead of one range where you have the comma separated values. There should not be a functional difference but it would make your code clearer.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans