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 :
Finance | Project Operations, Human Resources, ...
Answered

Query object relations missing

(0) ShareShare
ReportReport
Posted on by 17

Hello developers,

I created a query object to cycle through transfer order lines, headers and pickroutes with that data source hierarchy. I tried to 'use relations' to tie the data sources together, that didn't work. adding the relation ships on the data sources didn't work either. The joins are there, but the 'join on' criteria - the relations - are not there no matter what I do. What am I missing ?

+ transferOrderQuery {Query rsmglf_TransferOrdersQuery object c96aa190: SELECT * FROM InventTransferTable(InventTransferTable) JOIN * FROM InventTransferLine(InventTransferLine) JOIN * FROM WMSPickingRoute(WMSPickingRoute) WHERE ((InventTransferTable(InventTransferTable).))} Dynamics.AX.Application.Query

Best regards

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

    Hi Mike,

    What exactly do you mean with adding the relation ship on the data sources. Where have you done exactly what? Can you share a screenshot of the query with one of the joins and their properties?

  • Mike Jones II Profile Picture
    17 on at

    André,

    sure, here are some screenshots. I tried this after the 'use relations=yes' did not work. 

    pastedimage1587161966541v1.png pastedimage1587162006453v2.png

  • Mike Jones II Profile Picture
    17 on at

    The query is a parameter on a batch job (SysOpFw)

    It shows like that before I even add additional ranges. It pulls the first record (transfer line) correctly and the two other two are likely the first one it finds ignoring the criteria.

    Query transferOrderQuery;
    QueryRun transferOrderQueryRun;

    createdDate = DateTimeUtil::date(_contract.parmCreatedDate());
    transferOrderQuery = _contract.getQuery();

    transferOrderQuery.dataSourceTable(tableNum(inventTransferTable)).addRange(fieldNum(InventTransferTable,ShipDate)).value(SysQuery::range(_contract.parmFromDate(), _contract.parmToDate()));
    transferOrderQuery.dataSourceTable(tableNum(inventTransferTable)).addRange(fieldNum(InventTransferTable,CreatedDateTime)).value(SysQuery::range(createdDate, _contract.parmToDate()));

    transferOrderQuery.dataSourceTable(tableNum(InventTransferLine)).addRange(fieldNum(InventTransferLine,QtyRemainShip)).value('>' +any2Str(_contract.parmQtyRemain()));

    transferOrderQueryRun = new QueryRun(transferOrderQuery);

    while (transferOrderQueryRun.next())
    {
    inventTransferLine = transferOrderQueryRun.get(tableNum(InventTransferLine));

    inventTransferTable = transferOrderQueryRun.get(tableNum(InventTransferTable));
    pickRoute = transferOrderQueryRun.get(tableNum(WMSPickingRoute));

  • André Arnaud de Calavon Profile Picture
    300,911 Super User 2025 Season 2 on at

    Hi Mike,

    Did you try to do a database sync after the build?

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Mike,

    Have you tried to reset the query from the dialog? it could be that relations are unpacked from previous runs.

  • Mike Jones II Profile Picture
    17 on at

    Sergei,

    yes, I did after I read your post. That didn't change anything but I think we're headed into the right direction. I actually DELETED the query since I needed a different hierarchy anyways. I did a full build/sync and yet the old query (possibly the very first instance before I had any relations created) shows up at runtime.

    {Query abc_TransferOrdersQuery object 852a2e10: SELECT * FROM InventTransferTable(InventTransferTable) JOIN * FROM InventTransferLine(InventTransferLine) JOIN * FROM WMSPickingRoute(WMSPickingRoute) WHERE ((InventTransferTable(InventTransferTable).))}

    This query executed does no longer exist. The file is gone. The only two relevant areas use the new query: 

    [DataMemberAttribute, AifQueryTypeAttribute('_packedQuery', querystr(abc_TransferOrderLineQuery))
    ]
    public str parmPackedQuery(str _packedQuery = packedQuery)
    {
    packedQuery = _packedQuery;

    return packedQuery;
    }

    public void initQuery()
    {
    // Use this method to add ranges etc. for example:
    Query newQuery;
    // init Query
    newQuery = new Query(queryStr(abc_TransferOrderLineQuery));

    this.setQuery(newQuery);
    }

    This must be some sort of caching problem. I'm also unable to actually hit the break point in my data contract for those two methods.

    Best regards

  • Verified answer
    Frank Bruemmer Profile Picture
    354 on at

    Mike,

    your query might be cached in the usage settings. Go to user settings/usage data and look in 'all usage data'. Clear if necessary.

    And this is user based. Make sure to clear for the user that runs the query, which could be different also. Check what user is running when you run the debugger.

  • Vishals786 Profile Picture
    on at

    Hi Mike , 

    As you already have created the field relation manually after making "Use Relation" Property to Yes.

    Can you try adding your query to a form or a view and check if the query is returning required results or not. 

    Sometimes in D365 FO this happens that the values do not populate properly at the time of creation but after a full build and sync if the query is attached to an

    object it starts working.

    Can you try this once and let us know.

    Thanks and Regards

    Vishal Sahijwani

  • Mike Jones II Profile Picture
    17 on at

    Thanks, this is it. After I cleared out the usage data, the real query information was pulled including the right relations.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans