Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

How can I filter my records to show all records in the main table?

(0) ShareShare
ReportReport
Posted on by 65

Hello everyone,

I need to use onlookup event to filter my data based on another table in form.
I have inventsite form and 2 tables with 1:N relation in it. One of them is SitePI and other one PITrans.

Here is the scenario: I go to InventSite form and add a site named test and I go to SitePI table ( it is in the fast tab) I add records (001, 004, 005), I add another site named test2 and add records 003,006,007 for its SitePI. lastly, I go to PITrans table ( It is in the another fast tab,) and when I press the drop-down I need to able to select records that belong to SitePI table as lookup.


But I can see only the selected record.

Screen-Shot-2021_2D00_07_2D00_06-at-18.17.51.png

I need to see 001, 004 and 005 when I select records. 

Here is my code ( PICode is RefRecId for my lookup table)

[FormControlEventHandler(formControlStr(InventSite, PITrans_PICode), FormControlEventType::Lookup)]
    public static void PITrans_PICode_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        SysReferenceTableLookup tableLookup = SysReferenceTableLookup::newParameters(tableNum(SitePI), sender);
        Query query = new Query();

        SitePI sitePI = sender.formRun().dataSource('SitePI').cursor();
        InventSite inventSite = sender.formRun().dataSource('InventSite').cursor();

        QueryBuildDataSource qbds = query.addDataSource(tableNum(SitePI));
        
        qbds.addRange(fieldNum(SitePI, PICode)).value(queryValue(sitePI.PICode));
       

        query.dataSourceTable(tableNum(SitePI)).addOrderByField(fieldNum(SitePI, PICode), SortOrder::Ascending);

        tableLookup.addLookupField(fieldNum(SitePI, PICode));
        
        tableLookup.parmQuery(query);
        tableLookup.performFormLookup();

        FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
        ce.CancelSuperCall();

I would be really appreciated it if anyone can help me. 

Regards 

jennifer

  • YCeren Profile Picture
    65 on at
    RE: How can I filter my records to show all records in the main table?

    Hi Danilo

    Yes, I have a relation between these two tables because of the lookup but I think the problem is something else; index of SitePI table includes InventSite and PICode fields. I know that's why the system shows me these but I cannot delete InventSite from the index. Is there any way to hidden it when I select record from lookup? Maybe add some code but I do not know how.

  • greengrimms Profile Picture
    1,400 on at
    RE: How can I filter my records to show all records in the main table?

    Hi again Jennifer,

    By any chance, have you added a relation between those two tables (SitePI and PITrans)?

  • YCeren Profile Picture
    65 on at
    RE: How can I filter my records to show all records in the main table?

    I have one more problem. While I select PI code it's okay but once I select it, it shows both PI code and Id of the selected site but I want to see only PiCode. 

    If there is any advise about that that would be great for me.

    Thank you very much...

    Screen-Shot-2021_2D00_07_2D00_07-at-18.54.44.png

  • YCeren Profile Picture
    65 on at
    RE: How can I filter my records to show all records in the main table?

    Thank you very much for your answer. If I delete the range then I will get all the records includes all sites but I want to get the records that belong selected site. So I made this change and now I can see all the records that belong to only selected site. 

    qbds.addRange(fieldNum(SitePI, InventSite)).value(queryValue(sitePI.InventSite));

  • Verified answer
    greengrimms Profile Picture
    1,400 on at
    RE: How can I filter my records to show all records in the main table?

    Hi Jennifer,

    That's happening due to this piece of code:

    qbds.addRange(fieldNum(SitePI, PICode)).value(queryValue(sitePI.PICode));
    '

    addRange() is used to filter out the results in the query, so what you're effectively doing there, is filtering out all the other PICodes, except for 004, which is the one you have selected on the first grid, and you're obtaining the selected record with this sentence:

    SitePI sitePI = sender.formRun().dataSource('SitePI').cursor();

    So if you delete your range, you should be able to populate your lookup with all the values you need.

    Hope it helps.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,245 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,925 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans