web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Error executing code: The field with ID '0' does not exist in table 'OMHierarchyRelationship'.

(0) ShareShare
ReportReport
Posted on by 120

Trying to show the OMOperatingUnit lookup based on the selected  hierarchy.
Created a query and that query fetched values are showing in the lookup.
But after seleceting the values. getting the below error

Error executing code: The field with ID '0' does not exist in table 'OMHierarchyRelationship'.

Stack trace

(C)\Classes\SysLookupMultiSelectGrid\getSelected - line 34
(C)\Classes\SysLookupMultiSelectGrid\run - line 38
(C)\Classes\SysLookupMultiSelectGrid\lookup - line 10
(C)\Classes\SysLookupMultiSelectCtrl\ctrlNames_lookup - line 3

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    303,446 Super User 2026 Season 1 on at

    Can you share the code you used and also tell how the query looks like? That would make it more clear what might be missing. Have you created a list with fields on the datasource of the query?

  • ndakota033 Profile Picture
    120 on at

    MyTableOrganizationHierarchyTypeParameters      orgHierarchyTypeParameter;

       QueryBuildDataSource                        qbdsOMHierarchyRelationship,qdbsOperatingUnit;

       Query orgUnitQuery                          = new Query();

       select firstOnly MyField from orgHierarchyTypeParameter;

       qbdsOMHierarchyRelationship = orgUnitQuery.addDataSource(tableNum(OMHierarchyRelationship));

       qbdsOMHierarchyRelationship.addRange(fieldNum(OMHierarchyRelationship, HierarchyType)).value(strFmt('%1',orgHierarchyTypeParameter.MyField ));

       qdbsOperatingUnit = qbdsOMHierarchyRelationship.addDataSource(tableNum(OMOperatingUnit));

       qdbsOperatingUnit.addLink(fieldNum(OMHierarchyRelationship,ChildOrganization),fieldNum(OMOperatingUnit, RecId));

       qdbsOperatingUnit.fields().clearFieldList();

       orgUnitQuery.clearAllFields();

       qdbsOperatingUnit.fields().addField(fieldNum(OMOperatingUnit,OMOperatingUnitNumber));

       qdbsOperatingUnit.fields().addField(fieldNum(OMOperatingUnit,Name));

       qdbsOperatingUnit.addOrderByField(fieldNum(OMOperatingUnit,OMOperatingUnitNumber));

       msCtrlOrgUnit = SysLookupMultiSelectCtrl::constructWithQuery(element, MyControlName, orgUnitQuery);

  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    Hi ndakota033,

    You get this issue because you cleared all fields from first data source with this line orgUnitQuery.clearAllFields();

    AX tries to get default field and it is first selection field in first data source, however you don't have any.

    So remove this line and everything should be ok or you can try to specify selection fields, it is last parameter of constructWithQuery() method.

  • ndakota033 Profile Picture
    120 on at

    Hi,

    If I delete that line , in dropdown it is showing all the fields from the table.

    Thats why I have wrote orgUnitQuery.clearAllFields();

  • ndakota033 Profile Picture
    120 on at

    Yes Its working after commenting that line.

  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    can you swap your data sources ?

    If you will make OMOperatingUnitNumber first one and will join OMHierarchyRelationship to it everything would be ok as well.

  • Verified answer
    André Arnaud de Calavon Profile Picture
    303,446 Super User 2026 Season 1 on at

    Assuming you would like to have the operating unit as lookup field, I would also swap the data sources and use the OMHierarchyRelationship only for filtering purpose.

  • ndakota033 Profile Picture
    120 on at

    No.

    Its working now but I am able to see all the fields value in the lookup.

    which I dont want  :(

    lastParameter is not working . I have already tried

  • Mea_ Profile Picture
    60,286 on at

    Did you swap your data sources ?

  • Verified answer
    ndakota033 Profile Picture
    120 on at

    Hello Ievgen and Andre,

    Its working fine now.

    I have changed 3 things.

    1. Swap the datasource

    2. make the 2nd datasource dynamic property to No

    3. Delete the orgUnitQuery.clearAllFields();

    Now the code looks like

    MyTable orgHierarchyTypeParameter;
    QueryBuildDataSource qbdsOMHierarchyRelationship,qdbsOperatingUnit;
    Query orgUnitQuery = new Query();

    select firstOnly Myfield from orgHierarchyTypeParameter;

    qdbsOperatingUnit = orgUnitQuery.addDataSource(tableNum(OMOperatingUnit));

    qdbsOperatingUnit.fields().clearFieldList();

    qdbsOperatingUnit.fields().addField(fieldNum(OMOperatingUnit,OMOperatingUnitNumber));
    qdbsOperatingUnit.fields().addField(fieldNum(OMOperatingUnit,Name));
    qdbsOperatingUnit.addOrderByField(fieldNum(OMOperatingUnit,OMOperatingUnitNumber));

    qbdsOMHierarchyRelationship = qdbsOperatingUnit.addDataSource(tableNum(OMHierarchyRelationship));

    qbdsOMHierarchyRelationship.addRange(fieldNum(OMHierarchyRelationship, HierarchyType)).value(strFmt('%1',orgHierarchyTypeParameter.MyField));
    qbdsOMHierarchyRelationship.fields().dynamic(NoYes::No);
    qbdsOMHierarchyRelationship.fields().clearFieldList();

    msCtrlOrgUnit = SysLookupMultiSelectCtrl::constructWithQuery(element, MyControlName, orgUnitQuery);

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Sagar Suman Profile Picture

Sagar Suman 2 Super User 2026 Season 1

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans