Couldn't Set Query on Joined Form Data Sources

Hi all.

I have an issue in Dynamics Ax that I could not set query on joined form data sources. I have to set the query so that I could get the query back to the former query before I add the link into the query. I have the requirement to remove only few links between query data sources. As I know, AX only has method to remove all the links with clearLinks(). So I have to be a little bit tricky by copy the query first into the temporary query before I start to add link into the query.

_queryTemp = new Query(purchLine1_ds.query());

So, when I want to remove that link, I only need to set the query with the temporary query that I have copied before.

PurchLine1_ds.query(new Query(_queryTemp));

I have successfully used this workaround several times. But, I just realized I can’t used this method anymore since the form datasource which I set the query is the joined datasource and it issued an error.

Is there any workaround or another method? Thanks.

Could we return back from details of your implementation to your actual requirement? Why are you removing links? Can’t you simply disable linked data sources? And what’s the problem with clearLinks()?

Thank you Martin for your response. The detail is here. I want to modify the PurchLineBackOrder form in AX 2012R3. I want to add the ItemBuyerGroupId and Department filter which both of them were in PurchTable and DefaultDimensionView. As long as the grid data source is InventTrans table and the form doesn’t have PurchTable and DefaultDimensionView as its data sources, I need to add link between the InventTrans and both of the tables when the I enter the filter. But when I clear the filter, I think I couldn’t simply just use clearLinks() because it will remove all of the links that were initialized in init() or other standard methods defined by AX in that form. So I try to get the query to temporary query before I add the link and when I clear the filter, I set the datasource query with that temporary query to generate the data fully without any links or filter.

  1. Is there any method to clear the specific link with another table(not all of the links)?

  2. Is there any method to set the query on joined form data source (if the datasource was not joined, this method is run smoothly)?

Thanks

Why don’t you merely remove the value of the filter?

Also, if you remove join conditions (= links) but you don’t remove joined data sources, you get cross-joins, won’t you? It doesn’t sound like what you wanted.

If removing the filter isn’t enough, disable data sources.

  1. If I remove the value of the filter, the link is still exist there. It means that it would still search the data which has the value zero or ’ '.

  2. Hmm what does the cross-join mean? What I wanted is I could set the query to the form before I add the links (back to the AX standard model). Because when I clear all the links → clearLinks(), I need to manually add the links again which had defined in the init or other standard methods defined by AX and I was just so hard to understand the standard code.

  3. How to disable data source? Why should I disable it since the grid data was based on it?

  1. No, if you search for ’ ', you didn’t correctly removed the filter. Either delete the range completely, or keep it and set its value to SysQuery::valueUnlimited().
  2. en.wikipedia.org/wiki/Join_%28SQL%29#Cross_join. Check the resulting query string to see what exactly are you sending to database.
  3. enabled(false)
  1. Delete the range? Did you mean by using clearRange()?

  2. Okay, I’ll check it out.

  3. Why do I have to disable the datasource since the grid was based on it?

  4. I’m sorry for the noob question. Where should I put the .addLink method correctly according to you? In init() or when the filter value is exist?

  5. So, the AX doesn’t have a method to remove the specific link other than clearLinks()?

Yes, if you’re using QueryBuildRange, you can remove it by calling QueryBuildDataSource.clearRange(). Or you can keep it in place and allow all values, as explained before.

“Why do I have to disable the datasource since the grid was based on it?” - I mean the linked data sources.

“Where should I put the .addLink method correctly?” - I can’t answer it, because I don’t know what you’re doing with it. Maybe you should create links at design time, maybe when initializing the form, maybe when adding a specific filter…

“So, the AX doesn’t have a method to remove the specific link other than clearLinks()?” - No, but it’s not a big problem. You can remove all links and recreate those you need. Note that removing a link is not very common.

  1. QueryBuildDataSource.clearRange() is not enough in this case. Because before I add the range, I add the links with the JoinMode as ExistsJoin which means the data had been filtered if it has the relation with the other table. I had tried it.

  2. I tried to remove the JoinSource property in the datasource and manually add the relation by the X++ code. However, the data appeared in the grid is different from filling the JoinSource property.

  3. Sure it’s a big problem for me. Why does the clearRange (for the specific field range) exist when the clearLink (for the specific link) not exist? If I remove all links and recreate it, I couldn’t make it similar as the data firstly appears by the standard AX code init() and the other standard methods which run first in initialization. And if I successfully could remove all the links and recreate it, what about the performance? I’m sure it’s far slower rather than removing only the specific link.

I already told you how to do it: disable the joined data source by calling enabled(false).

If you need any additional advice, please tell us what exactly your data sources and how they’re linked, what code you put into init() method etc. It will save time for both of us.

I said that “If removing the filter isn’t enough, disable data sources” in my second reply - if you told me that you don’t want to keep the data source enabled, I wouldn’t even suggested removing filters. And all the following discussion about filters wouldn’t happen if you realized that the condition (“If removing the filter isn’t enough”) is met in your particular case.