Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 17314

How to: Pass different data source records to Class

$
0
0

Good day everyone,

Last time I taught How to: Pass multiple data source records to Class, I know there is better ways to do this like using the class MultiSelectionHelper which I will post about it next week. But the problem is when the form data source it’s not what you want. For example, on SalesTable form, I need to pass the RecId from SalesLines to class but the form’s data source by default is SalesTable. In this case I have to force the Args to pass the data source that I want.

First, have you used the following code to validate if the args.record() has what you want?

if  (_args.record().TableId == tableNum(custTable))
{
     custTable      = _args.record();
}

If it returns FALSE and you don’t know why, one possible reason it’s because the form data source is different fron what you expected.
Let’s insert 2 additional codes on main method right after variable declaration.

info(strFmt('%1' , tableNum(salesTable)));
info(strFmt('%1' , _args.record().TableId));

Now, execute the code and wait for Information Log to pop-up. Compare TableNum and Args.Record().TableId on Info Log.

ScreenClip

We know that the tableID are different, if you are not familiar with the IDs check this post to know how to get table name through SQL Query.
And then using the SQL Query I saw why it is not working. The Form DataSource and Grid DataSource are not the same and we are passing the wrong Args records!

ScreenClip

A simple workaround is to force the DataSource CustTable on Args. To do this, first set the button Auto Declaration to Yes and Display Target to Client.

Now, override the button Clicked method and use the code below:

void clicked()
{
    MenuFunction    menuFunction;
    Args            args;
    ;

    args            = new Args();

    //Set CustTable as Args.Record() as DataSource.
    args.record(CustTable);

    //Create the MenuItem Display through X++
    menuFunction = new menufunction(identifierstr(CustTableListPageDialog), MenuItemType::Display);
    menuFunction.run(args);
}

Ok, I hope with the steps above you were able to solve your problem. Let’s check the results.

ScreenClip

ScreenClip



Viewing all articles
Browse latest Browse all 17314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>