Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Create Custom Lookup
Finance forum

Create Custom Lookup

(0) ShareShare
ReportReport
Posted on by 245

Hi,

I create a custom lookup with multiple table on lookup field

This is my code : 

[FormControlEventHandler(formControlStr(smmOpportunityTable, PartyGroup_Name), FormControlEventType::Lookup)]
    public static void PartyGroup_Name_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        FormDataSource fds = sender.formRun().dataSource("smmOpportunityTable");
        smmOpportunityTable opp = fds.cursor();
        Query                   query = new Query();
        QueryBuildDataSource    qbds, qbds2;
        QueryBuildDataSource    qbdsJoin;
        SysTableLookup          sysTableLookup = sysTableLookup::newParameters(tableNum(DirPartyTable), sender);

        qbds = query.addDataSource(tableNum(DirPartyTable));
        qbds2 = qbds.addDataSource(tableNum(smmBusRelTable));
        qbds2.addLink(fieldNum(DirPartyTable, RecId),fieldNum(smmBusRelTable, Party));
      
        

        sysTableLookup.parmQuery(query);
        sysTableLookup.addLookupfield(fieldNum(DirPartyTable, Name), true);
        sysTableLookup.addLookupfield(fieldNum(DirPartyTable, PartyNumber));
        sysTableLookup.addLookupfield(fieldNum(smmBusRelTable, BusRelAccount));
        sysTableLookup.performFormLookup();

        FormControlCancelableSuperEventArgs event = e as FormControlCancelableSuperEventArgs;
        event.CancelSuperCall();
    }

This is the result : 
7180.1.png

Thanks

  • Verified answer
    adam260 Profile Picture
    adam260 1,871 on at
    RE: Create Custom Lookup

    They dropped the class/ability to use SysMultiTableLookup in 2012 R3. IMO the best way to do this is just create a view and use that as your single datasource

  • Verified answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: Create Custom Lookup

    Hi Rangaa!

    SysTableLookup does not support more than 1 datasource.

    There are few possible workarounds:

    1. Use open source solution SysMultiTableLookup as Hossein Karimi was suggested

    2. Create view that contain needed tables as a datasource

    3. Create display method and using it (sysTableLookup.addLookupMethod())

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,642 on at
  • Rangga Pramana Profile Picture
    Rangga Pramana 245 on at
    RE: Create Custom Lookup

    I wrote my code like this  :

    [FormControlEventHandler(formControlStr(smmOpportunityTable, PartyGroup_Name), FormControlEventType::Lookup)]
        public static void PartyGroup_Name_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            FormDataSource fds = sender.formRun().dataSource("smmOpportunityTable");
            smmOpportunityTable opp = fds.cursor();
            Query                   query = new Query();
            QueryBuildDataSource    qbds, qbds2;
            QueryBuildDataSource    qbdsJoin;
            SysTableLookup          sysTableLookup = sysTableLookup::newParameters(tableNum(DirPartyTable), sender);
            
    
            qbds = query.addDataSource(tableNum(DirPartyTable));
            qbds2 = qbds.addDataSource(tableNum(smmBusRelTable));
            qbds2.addLink(fieldNum(DirPartyTable, RecId),fieldNum(smmBusRelTable, Party));
    
            sysTableLookup.parmQuery(query);
            sysTableLookup.addLookupfield(fieldNum(DirPartyTable, Name), true);
            sysTableLookup.addLookupfield(fieldNum(DirPartyTable, PartyNumber));
            sysTableLookup.addSelectionField(fieldNum(smmBusRelTable, BusRelAccount));
            
            
            sysTableLookup.performFormLookup();
    
            FormControlCancelableSuperEventArgs event = e as FormControlCancelableSuperEventArgs;
            event.CancelSuperCall();
        }

    It's doesn't work :(

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,391 Super User 2024 Season 2 on at
    RE: Create Custom Lookup

    Hi Rangga,

    You have to add a command called sysTableLookup.addSelectionField(fieldNum(....,...)). This line is missing.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans