Good day everyone,
Today I will continue talking about how to pass multiple records to class, this time I will do it using the helper class MultiSelectionHelper. The MultiSelectionHelper class provides an interface to work with multiple selected records on a form data source and which can be cached, if called on server it will be cached by default.
For the sake of example purpose, I have modified a project which I had to reset all the remainder quantity of selected rows. I will change it a bit to show instead the selected rows RecId.
1. Create the class which will receive Args from our MenuItemButton.
2. On classDeclaration, declare the Table Buffer:
3. Create the method main and use the following code:
Not all times the Grid DataSource will be the same as Args.Record(), in this case you can’t use MultiSelectionHelper and will have to do it “Manually” you can do it following my other post. If you don’t know which Table is it by the TableID, you can use a SQL query to discover it.
4. This is the method which will be used to create the Dialog and it’s here that we are going to use MultiSelectionHelper.
In the example above we received the caller form with the _args object. Then, we have to find the correct FormDataSource object. This should be the table for which we want to get the list of records. After getting the correct data source, we can then tell the selection helper object to create ranges for the selected records on the specified QueryBuildDataSource, which we can now get directly from the FormDataSource in Dynamics AX 2012, with the queryBuildDataSource method. Then I created a Dialog asking if the user wishes to continue operation, if he confirms it will show RecId on the Infolog.
5. Create the Menu Item Display. For example, I have set the following properties.
6. Now, on the PurchLineBackOrderListPage form Design locate the ActionPaneTab, create a Button Group and then drag and drop the MenuItem to Button Group. It should look like this:
7. For your information, I have set the following properties:
|ButtonDisplay||Text & Image right|
8. Now we are done! I hope my posted has saved you some time.