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, ...
Answered

Add filter to DirPartyLookup

(0) ShareShare
ReportReport
Posted on by 50

My new table has a new field that reference dirparty and another field to relate dirparty contact person

I want to create a lookup for this field in my new form. The problem is I need to filter record in dirparty to show only contact person related on the reference dirparty

For example

My table

Parent party : A

Contact person party : I need this field to lookup contact person for party A

I've tried to use these lines of code but it shows error.

public Common lookupReference(FormReferenceControl _formReferenceControl)
{
Common ret;

ret = ContactPerson::lookupContactPersonByContactForParty(_formReferenceControl, FlxUs_BookingOpportunityParty.Party);

return ret;
}

Error : Could not process the lookupRecord value on the Args instance. The table 'DirPartyTable' does not exist as a root FormDataSource for the form 'XXTable__GridPartyContacts_ContactPersonParty'

Any ideas to resolve this issue?

I have the same question (0)
  • AstridMalanka Profile Picture
    8 on at

    did you add the source before adding the code?

  • André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    Hi Atiraj,

    When you paste coding on this forum, please use the rich formatting and then Insert > Coding. It will then be better readable. 

    public Common lookupReference(FormReferenceControl _formReferenceControl)
    {
        Common ret;
    
        ret = ContactPerson::lookupContactPersonByContactForParty(_formReferenceControl, FlxUs_BookingOpportunityParty.Party);
    
        return ret;
    }

    Can you tell us where exactly you added this method? Did you use the debugger to find out if this coding is causing the issue or another statement?

  • Atiraj Profile Picture
    50 on at

    I add this method in form datasource field

    lookupContactPersonByContactForParty method will use systableformreference when it call performformlookup, that's where error occur.

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    I created a similar table, tried your code and found that it works fine. Your problem is caused by something else.

    Are you able to catch the exception? If so, isn't there anything interesting in StackTrace?

  • Atiraj Profile Picture
    50 on at

    pastedimage1661322216104v1.png

    pastedimage1661322241264v2.png

    Here's where the error occur.

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    May I ask you once more to get the call stack of the exception? Just showing me the code doesn't tell me much about the actual situtation at runtime.

    Also, because we know that problem must be caused by something else than lookupContactPersonByContactForParty(), let's review your implementation. First of all, did you override lookupReference() of the right control?

    What is XXTable__GridPartyContacts_ContactPersonParty? Is it the name of your form?

  • Atiraj Profile Picture
    50 on at

    pastedimage1661324893146v1.png

    did you override lookupReference() of the right control?

    >>Yes, I override lookupreference method in Contactparty field in FormDatasource

    What is XXTable__GridPartyContacts_ContactPersonParty? Is it the name of your form?

    >> It is the name of reference group object in grid

  • Verified answer
    Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    Aha, it generates a form at runtime and its name contains names of the caller form and control.

    I think that the form gets generated correctly (with ContactPerson as the root data source), but then it tries to find a DirPartyTable record there, which is wrong. This doesn't happen in my environment - it does look for a ContactPerson record as expected. (I added some code to check the value of .args().lookupRecord() of the generated form.)

    Do you get the error when opening the lookup with no value in the field, or just when opening it with something already specified?

    When things behave weird, it doesn't harm if you re-compile the whole model and try it again. Then I would review everything to make sure that it's correct. Unfortunately we won't be able to debug all the related logic, because a lot of it is in AX kernel.

  • Atiraj Profile Picture
    50 on at

    Thanks for your help

    I think I found the problem!

    Because my "Contact party" field has relation with DirPartyTable, that's why it tries to find DirPartyTable record.

    Therefore, I can't use this method, I have to create SysReferenceTableLookup with DirPartyTable

    Here's the line of code that solve the problem

    public Common lookupReference(FormReferenceControl _formReferenceControl)
    {
        Common ret;
        SysReferenceTableLookup sysRefTableLookup   = SysReferenceTableLookup::newParameters(tableNum(DirPartyTable), _formReferenceControl);
        Query                   query               = new Query();
        QueryBuildDataSource    qbd;
        QueryBuildRange         qbr;
    
        query.addDataSource(tableNum(DirPartyTable));
        qbd = query.dataSourceTable(tableNum(DirPartyTable)).addDataSource(tableNum(ContactPerson));
        qbd.addLink(fieldNum(DirPartyTable, RecId), fieldNum(ContactPerson, Party));
        
        qbr = qbd.addRange(fieldNum(ContactPerson, ContactForParty));
        qbr.value(SysQuery::value(queryValue(MyTable.ParentParty)));
    
        // Add fields
        sysRefTableLookup.addLookupfield(fieldNum(DirPartyTable, Name));
        sysRefTableLookup.addLookupfield(fieldNum(DirPartyTable, PartyNumber));
        sysRefTableLookup.addLookupfield(fieldNum(DirPartyTable, NameAlias));
        sysRefTableLookup.addLookupMethod(tableMethodStr(DirPartyTable, type));
    
        // Run lookup
        sysRefTableLookup.parmQuery(query);
        ret = sysRefTableLookup.performFormLookup();
    
        return ret;
    }

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    Your code assumed that you have a reference to ContactPerson table. That's how I implemented my table and everything worked correctly.

    I wonder whether you shouldn't use this setup too. Wouldn't a reference to ContactPerson be more appropriate than to DirPartyTable? It seems to make logic sense and it gives you not just reference to the conctant person's Party, but also other information defined in ContactPerson table, such as OfficeLocation, information whether it's still active and so on.

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

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans