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)

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
    300,955 Super User 2025 Season 2 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,284 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,284 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
    300,955 Super User 2025 Season 2 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,284 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

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans