Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Override lookup method in AX 2012

Posted on by Microsoft Employee

Hi 

I am creating override lookup form method and am trying to show the second column field value in a lookup in AX 2012. This screenshot just to show u reference.

I need to get the second field value on selected record in the lookup .

3034.lookup.png

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Override lookup method in AX 2012

    link to photo: https://imgur.com/a/hQSBhhN

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Override lookup method in AX 2012

    Hi,

    I know it is very old post, but I'm new in AX. I have solution sth like this to your problem:

    1. Find DS and field whose is ID on lookup and override modified() method

    <img src="imgur.com/.../hQSBhhN&quot; />

    2. Use Select to find your field (this is example for this screen)

    public void modified()

    {

       smmBusRelTable              sBRelTable;

       DirPartyTable               dPartyTable;

       super();

       select Party from sBRelTable //RecId

           where sBRelTable.BusRelAccount == GoExperience_GoCompanyCode.valueStr() // GoExperience_GoCompanyCode - value on design/grid

           join Name from dPartyTable

               where  dPartyTable.RecId == sBRelTable.Party; //Party is as RecId field

       GoExperience.GoCompanyName = dPartyTable.Name; //and now it's working

       GoParticipants_ds.refresh();

       GoParticipants_ds.research();

    }

    Regards

  • Suggested answer
    startax Profile Picture
    startax 1,845 on at
    RE: Override lookup method in AX 2012

    Hi Priyabrata

    If I am right your are trying to display Description field to user and store Name in table ?

    For this requirement you have to use replacement group

    You can find more details on below link

    community.dynamics.com/.../replacement-groups-in-ax-2012

    dev.goshoom.net/.../&nbsp;

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,642 on at
    RE: Override lookup method in AX 2012

    Hi,

    please check this link;

    https://msdn.microsoft.com/en-us/library/hh185372.aspx

  • Suggested answer
    Ammar Abbasi Profile Picture
    Ammar Abbasi 52 on at
    RE: Override lookup method in AX 2012

    Hi Priyabrata,

    Modify the code as follows:

    Your lookup method should be:

     Query                   query = new Query();
    
                QueryBuildDataSource    queryBuildDataSource;
    
                SysTableLookup  sysTableLookup = sysTableLookup::newParameters(tableNum(InventSite), this);
    
                ;
    
                sysTableLookup.addLookupfield(fieldNum(InventSite, SiteId), true);
    
                sysTableLookup.addLookupfield(fieldNum(InventSite, Name));
    
                queryBuildDataSource = query.addDataSource(tableNum(InventSite));
    
                queryBuildDataSource.addSortField(fieldnum(InventSite, SiteId));
    
                queryBuildDataSource.addOrderByField(fieldnum(InventSite, Name));
    
                queryBuildDataSource.orderMode(OrderMode::GroupBy);//Used to Group the Field Value
    
                sysTableLookup.parmQuery(query);
    
                sysTableLookup.performFormLookup();
    Create a new class with the following code:
    class LookupFormClass
    {
        public InventSiteName getInventSiteName(InventSiteId _inventSiteId)
        {
            return InventSite::find(_inventSiteId).Name;
        }
    
    }
    Now override the modified method in your field:
    public boolean modified()
            {
                boolean ret;
                LookupFormClass obj;
            
                ret = super();
    
                if (ret)
                {
                    obj = new LookupFormClass();
                    this.text(obj.getInventSiteName(this.text()));
                }
            
                return ret;
            }
    Hope that helps!
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Override lookup method in AX 2012

    Hi Ammar

    I have tried this one it's  not working my code is:-

    But, I need save the invoice Id other than name, in text field i can fetch the name but in table, i need to fetch the id.

       Query                   query = new Query();

       QueryBuildDataSource    queryBuildDataSource;

       SysTableLookup  sysTableLookup = sysTableLookup::newParameters(tableNum(InventSite), this);

       ;

       sysTableLookup.addLookupfield(fieldNum(InventSite, SiteId));

        sysTableLookup.addLookupfield(fieldNum(InventSite, Name), true);

       queryBuildDataSource = query.addDataSource(tableNum(InventSite));

       queryBuildDataSource.addSortField(fieldnum(InventSite, SiteId));

       queryBuildDataSource.addOrderByField(fieldnum(InventSite, Name));

       queryBuildDataSource.orderMode(OrderMode::GroupBy);//Used to Group the Field Value

       sysTableLookup.parmQuery(query);

       SysTableLookup.parmUseLookupValue(false);

       sysTableLookup.performFormLookup();

    Please suggest the solution.

  • Suggested answer
    Ammar Abbasi Profile Picture
    Ammar Abbasi 52 on at
    RE: Override lookup method in AX 2012

    Hi Priyabrata,

    I am assuming you are using SysTableLookup class to implement your lookup.

    You can set the second parameter to "true" while adding columns to your lookup.

    Please refer to the below sample code:

    public void lookup()
            {
                //super();
    
                SysTableLookup  lookup = SysTableLookup::newParameters(tableNum(CustInvoiceJour), this);
    
                lookup.addLookupfield(fieldNum(CustInvoiceJour, InvoiceId));
                lookup.addLookupfield(fieldNum(CustInvoiceJour, InvoicingName), true);  //returns the Invoicing Name
    
                lookup.performFormLookup();
            }


    Hope that helps!
  • RE: Override lookup method in AX 2012

    In InventJournalTable form, lookup method for the JournalNameId field is overwritten, you'll need to modify the designLookupJournalName method from the JournalFormTable class, ence you'll have to take a look at the JournalStatic class

    JournalName.JPG

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans