0

There is a form which is linked to the display menu item. I was checking the property of the menu item and see two properties have yes value, (1) neededRecord and (2) CopyCallerQuery. I discovered that when copyCallerQuery property is true, jumping to this form from other forms failed with this error :

Cannot apply initial query because no form root data source table matches the query root data source table..

On the other hand, in some situations this form is open by code in a helper class as bellow:

  private void openMyForm(MyTable _myTable)
    {
        MenuFunction    _menuFunction;
        Args            _args;
        _args           = new Args();

        _args.record(_myTable);
        _args.caller(this);
        _menuFunction   = new MenuFunction(menuItemDisplayStr(MyFormDisplayMenu),MenuItemType::Display);
        _menuFunction.openMode(OpenMode::Edit);
        _menuFunction.run(_args);
    }

When I set copyCallerQuery to No the form is open with wrong record but when I set it yes form is open with correct record. So I want to know what is usage of the CopyCallerQuery property? Did I use it correctly?

Nastaran Hakimi
  • 695
  • 1
  • 16
  • 36

1 Answers1

0

copyCallerQuery will specify if the calling form's query should be copied to the target form, for example copying a list page query to a details form.

You can see and better understand this for yourself by

  1. Create a form (Form1)
  2. Add a SalesTable datasource to it
  3. Override an init method at \Forms\Form1\Methods\init and after the super(); call put info(SalesTable_ds.query().toString());
  4. Create a Display menu item (\Menu Items\Display\Form1) with property Object = Form1 and CopyCallerQuery = Yes.
  5. Go to the SalesTable form at \Forms\SalesTable and just add that new menu item (Form1) anywhere on the SalesTable form as a button in the action pane, and set the datasource property to SalesTable
  6. Open the SalesTable form and press the button. Copy the infolog to notepad somewhere.
  7. Modify \Menu Items\Display\Form1 and set CopyCallerQuery = No and then open SalesTable form again and copy the query into notepad and compare the two.

Your error you are receiving is because the caller form's root datasource needs to match the target form's root datasource in order to copy it.

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • Dear Alex do you have any idea about the last paragraph of my question? – Nastaran Hakimi May 04 '20 at 16:16
  • Regarding the target form you are attempting to open; just inspect the query. In the `init()` method of the target form (after the `super();`), put `info(SalesTable_ds.query().toString());` and replace `SalesTable_ds` with whatever your form's root datasource is. Follow the steps I outlined and it should become clear to you. – Alex Kwitny May 04 '20 at 17:02
  • Dear Alex, I understand your post and usage the copy caller query. I explain the issue in the last paragraph in more details :I have two forms which data sources are not required to be match. I just want to open second form in my first form by code. I attach the code in my question. if the copy caller query is NO then second form opens with the first record not with the record I pass to the menu item. if the copy caller query is Yes then the form open with the record I pass. Is my issue clear? – Nastaran Hakimi May 12 '20 at 07:13
  • @NastaranHakimi I have answered your question clearly. You ask in the title, `What is the usage of the copy caller query property in display menu item in D365?` and in the body `So I want to know what is usage of the CopyCallerQuery property?`. I've explained it clearly. Your code that you've provided is generic and does not provide any meaningful detail to help us answer anything else. You need to follow the steps I have provided, examine the queries generated between the two methods you are using, and then determine if the query correctly retrieves the data you are seeking. – Alex Kwitny May 12 '20 at 15:11
  • If you have a question about the results of the query, you should create a new post with your new question and add more detail. The **only** thing unique in your code is `MyFormDisplayMenu`. Everything else is generic, so it provides no information to us. The last part you are asking, `Did I use it correctly?`, is impossible to answer without knowing both (1) the underlying queries produced and (2) what data/task you are trying to retrieve/accomplish. The answer to that question is "maybe? It depends." – Alex Kwitny May 12 '20 at 15:13
  • you wrote two comments just tell you don't know!. I will ask the issue in other question. Thanks – Nastaran Hakimi May 13 '20 at 03:40
  • @NastaranHakimi and I hit the character limit again with this comment, so I'm adding a second comment. You are **NOT** providing enough information to answer your question. It is **luck** that it works when you set that property. Nobody can answer "When I set copyCallerQuery to No the form is open with wrong record but when I set it yes form is open with correct record." It is equivalent to `I have a Form with 2 buttons, when I click button 1, it works. When I click button 2, it does not work. Why?`. Impossible to answer! We need to know what is behind the buttons like we need the query, etc. – Alex Kwitny May 13 '20 at 06:25
  • first of all I asked this question for knowing the usage of the copy caller query in menu items to understand it clearly. And your answer was helpful. but I had another issue which in the question I wasn't sure this is what copy caller query does or it is something like bug so I asked that too. As I accept the answer for the first section of my question, I'll add new question with the details of my issue. – Nastaran Hakimi May 13 '20 at 06:36
  • I think there is a language barrier here, and I'm not trying to be difficult or combative. I'm only saying there is not enough information in this post for anyone in the world to answer your second issue. It needs more information. A new post with additional details will be the best way to get the answer you are looking for regarding your second issue – Alex Kwitny May 13 '20 at 06:41
  • Thank you I will post a new question with additional details – Nastaran Hakimi May 14 '20 at 03:18