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)

Edit / Lookup method

(0) ShareShare
ReportReport
Posted on by 6,478

Hello,

I'm having trouble using the lookup or edit method.

In "create non conformance" form I want to display Operation names based on the type "Operation" and whatever value is in "Reference number" field.

I have added operation ID field in Table extension. With visible false.

I have also added Name in the table and in field group which is used on form.

The goal is this field to be lookup, which will show the list of "Route operation IDs" from table ProdRoute table / form and when selected you should get the name of that Operation.

Relations between tables are:

InventNonConformanceTable.InventRefId == ProdRoute.ProdId

ProdRoute.OprId == RouteOprTable.OprId

and I want to get RouteOprTable.Name value in my lookup field.

I didn't find much info about using of Edit method (Is it even possible to use in my case, as I want to display columns of one table when you click down arrow and when selected it to show the value from referenced table?)

For the lookup, I tried to build the method in table extension class, but I'm getting empty lookup.

Here is the code, which is not fully implemented with desired logic. Was just trying to be able to display columns from ProdRoute table.

[ExtensionOf(tablestr(InventNonConformanceTable))]
final class InventNonConformanceTableCreateXXX_Extension
{
    public static void routoprNameLookup(FormControl    _control,
                                        InventRefId   _inventRefId)
    {
        Query                   query;
        QueryBuildDataSource    qbds;
        QueryBuildRange         qbr;
        SysTableLookup          lookup;

        query = new Query();
        qbds = query.addDataSource(tableNum(ProdRoute));
        qbds = qbds.addDataSource(tableNum(InventNonConformanceTable));
        qbds.joinMode(JoinMode::InnerJoin);
        qbds.addLink(fieldNum(InventNonConformanceTable, InventRefId), fieldNum(ProdRoute, ProdId));
        qbr = qbds.addRange(fieldNum(ProdRoute, ProdId));
        qbr.value(queryValue(_inventRefId));

        lookup = SysTableLookup::newParameters(tableNum(InventNonConformanceTable), _control, true);

        lookup.parmQuery(query);
        lookup.addLookupfield(fieldNum(RouteOprTable, OprId));
        lookup.addLookupfield(fieldNum(RouteOprTable, Name));

        lookup.performFormLookup();
    }

}


And in form extension class I have:

[extensionOf(formStr(InventNonConformanceTableCreate))]
final class InventNonConformanceFormCreateXXX_Extension
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormControlEventHandler(formControlStr(InventNonConformanceTableCreate, myFormCOntrol), FormControlEventType::Lookup)]
    public void tmuTest_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        InventNonConformanceTable::routoprNameLookup(sender, this.InventNonConformanceTable.InventRefId);
        FormControlCancelableSuperEventArgs cancelSuper = e as FormControlCancelableSuperEventArgs;

        cancelSuper.CancelSuperCall();
    }

}



*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Fedir Kryvyi Profile Picture
    1,026 on at

    Johnny,

    Lets do it one by one:

    1. "The goal is this field to be lookup, which will show the list of "Route operation IDs" from table ProdRoute table / form and when selected you should get the name of that Operation." - in this case you are right to use lookup, but you would also need to modify modifiedField() method to set new value for "Operation Id" field value. Or you can override insert/update method to check if value in your second field was changed, and if so - set the value in another field

    2. I didn't find much info about using of Edit method (Is it even possible to use in my case, as I want to display columns of one table when you click down arrow and when selected it to show the value from referenced table?)

    you don't need to use Edit method in this case, both fields are present in one table, so you can just override table methods to populate second field after the first one is changed as I mentioned before

    3. "And in form extension class I have:" you need to cancel super, and only then to call your lookup

    and the last but not least - haven't you though to have RecId relation instead of storing Operation Id and Operation name? In this case you would be able to use ReferenceLookup to show both OperationId and Name columns, but store one value.

  • Johnny Profile Picture
    6,478 on at

    Hello Fedir,

    thanks for suggestions, I'll try them and approve answer after.

  • Johnny Profile Picture
    6,478 on at

    Hello Fedir,

    Could you give me some documentation / hints about the  referenceLookup?

    I added the new refrecId field to "InventNonConformanceTable" table and made a relation to ProdRoute table.

    But from what I know, reference group to work needs to have in related table "ProdRoute" unique index with "Alternate key" enabled and replacement key should be this index.

    I created new index in ProdRoute.extension, but table property "Replacement key" is not editable.

  • Johnny Profile Picture
    6,478 on at

    Hi Fedir,

    I created lookup with reference group as you suggested.

    It looks good, I see the fields.

    But, is it possible to add another field in this referenceLookup from different table? The table from where I want to display field is ProdRoute.

  • Suggested answer
    Fedir Kryvyi Profile Picture
    1,026 on at

    Hi Johnny,

    Sorry for the late response.

    You can create a lookup with fields from multiple tables by adding them in query that you are using for the lookup. Here is an example:

    community.dynamics.com/.../how-to-create-lookup-from-multiple-tables

    Please mark any of the messages above as suggested answer, if it solves you issue. Thx!

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