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 :
Microsoft Dynamics AX (Archived)

Simple Custyom LookUp of StringEdit won't work

(0) ShareShare
ReportReport
Posted on by

It's the nth time i'm having this issue, and i still can't figure out what causes it.
All my lookup are simple, just one or 2 fields and yet they don't work, not always at least. Sometimes they do, sometimes they don't.
i write the usual piece of code:

public void lookup(){
  Query                q;
  QueryBuildDataSource qbds;
  SysTableLoolup       stl = SysTableLookup::newParameters(TableNuma(LogisticsAddressCounty), this, true);

  qbds.addDataSource(tableNum(LogisticsAddressCounty));
  qbds.addLookupField(fieldNum(LogisticsAddressCounty, CountyId),true); //field is str
  stl.parmQuery(q);
  stl.performformLookup();
}

The StringEdit has the property LookupButton set to Always, so there's no excuse; the field type extends str, so no excuse, again.
This piece of code might work for you, it just doesn't work for me. 
I have another form with the same code zand it works there, and i have other stringedit controls with similar lookups that just won't work, setting breakpoints is useless since the method doesn't seem to be accessed, closed and reopened the client countless times. Updated the dictionary, the elements, the data and the report. Deteleted auc and kti files. Nothing works.
I don't even know how many hours i spent probing the internet for this problem, no one has experienced this particular issue, my collegues can't help as well
Another thing: one of the other lookups wsasn't working all day, i changed something completely unrelated from the lookup (added some str variable in class declaration i'm not even using) and suddently it started showing the results and the classic icon of the lookup (it still does).

Hope anyone has any idea. i finished them all.

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,075 Super User 2025 Season 2 on at

    Hi MatteoMario,

    Can't you use the default County lookup by specifying a table relation?

  • Community Member Profile Picture
    on at

    You say it works in one form and it doesn't in another. Try duplicating the one where it doesn't work and check if it works in the duplicate.

  • Community Member Profile Picture
    on at

    Hi

    sorry If I'm being wrong here.  could you try modifying the code little bit by specifying the FormStringControl  param.  

    public client static void lookupItem(FormStringControl _ctrl)

    {

       SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(InventTable),_ctrl);

       Query                   query = new Query();

       QueryBuildDataSource    queryBuildDataSource = query.addDataSource(tableNum(InventTable));

       sysTableLookup.addLookupfield(fieldNum(InventTable,ItemId));

       sysTableLookup.parmQuery(query);

       sysTableLookup.performFormLookup();

    }

    I had an issue earlier with lookups due to some issues in ds Active method. worth a try.

  • Community Member Profile Picture
    on at

    [quote user="Jens"]

    You say it works in one form and it doesn't in another. Try duplicating the one where it doesn't work and check if it works in the duplicate.

    [/quote]
    it doesn't...
  • Community Member Profile Picture
    on at

    [quote user="Manish "]

    Hi
    sorry If I'm being wrong here.  could you try modifying the code little bit by specifying the FormStringControl  param.  

    public client static void lookupItem(FormStringControl _ctrl)

    {

       SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(InventTable),_ctrl);

       Query                   query = new Query();

       QueryBuildDataSource    queryBuildDataSource = query.addDataSource(tableNum(InventTable));

       sysTableLookup.addLookupfield(fieldNum(InventTable,ItemId));

       sysTableLookup.parmQuery(query);

       sysTableLookup.performFormLookup();

    }

    I had an issue earlier with lookups due to some issues in ds Active method. worth a try.

    [/quote]it seems lookup item is a method of InventTable and ONLY InventTable. It's not in any of table i'm currently using. Therefore it won't ever be called unless i explicitly call it, whick is like trying to call it inside the method mouseDown().
    Anyhow i pass "this" to the static method newParameters, which in that scope is the FormStringControl, so there's no need to pass it as a parameter.

  • Community Member Profile Picture
    on at

    [quote user="André Arnaud de Calavon"]

    Can't you use the default County lookup by specifying a table relation?

    [/quote] I tried, the form is called and closed immediately. I even tried to invoke formrun.wait() performFormLookup() in the lookupCountyId() method and yes... it stays opened, yet it does it forever, impeding me from closing the lookup, thus the form itself. i have to close it from the task manager. 

  • Community Member Profile Picture
    on at

    Where did you put your code? You have to overwrite the lookup() method of the field in the form data source or of the control.

    The code you posted has quite a few errors. You should refer to the code of Manish -  it works.

  • Community Member Profile Picture
    on at

    [quote user="Jens"]Where did you put your code? You have to overwrite the lookup() method of the field in the form data source or of the control.[/quote]i don't have to, since my stringEdit is not connected to no datasource field, but i use (as i wrote in the initial post) a query to fetch the data.

  • Community Member Profile Picture
    on at

    Hi,

    Sorry, I didn't understand how you are invoking the lookup method. Could you explain little bit about how it is being called from form.

  • Community Member Profile Picture
    on at

    [quote user="Manish "]Could you explain little bit about how it is being called from form.[/quote]
    I override the lookup method of the string edit i need to populate (thanks to the lookup i'm trying to create). 

    4212.lookup.png

    Inside this method i put the code in the first post.
    The StringEdit is detached from any datasource. Adding an EDT makes no difference.
    The lookup method should be invoked automatically when the control is clicked.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans