I need to develop a button in Action Pane that will move selected records from that selected form to a new form.
What resources do I need? Queries, Menu Items, Jobs for example?
So basically you need to copy data from one table to another table, and then delete the row in the source?
Forms are just an artifact for presenting data. These data can be collected from the database or stored temporarily for presentation only.
AX will automatically link data between forms using Dynalink, as it has done all along:
Hello thanks for the answer.
I need to select records by checking chick boxes, and push on a button.
Then a new form opens with the selected records, but just a few fields.
Also the new form place a several additional textboxes who is used to override fields on the table when user press on OK button in the new form.
So, it's best just to filter the records to a new form, not copy records to a new table. Standard filtering should be OK.
You can easily get selected records with the help of MultiSelectionHelper class. You could do that even from the new form - just pass the right datasource (although you may prefer to pass an object with selected IDs or with a reference to a temporary table, depending on your implementation).
When you have IDs of selected records, you can add a range for each ID (or construct a single range value with OR operator), but it doesn't work well for higher number of values. The other option is to use a temporary table, either to be used directly in the new form, or to be used as a filter by joining with the original table (that's useful particularly with TempDB tables in AX2012). A temporary table would also make sense for your additional text boxes.
After I have look over all the requirements of the project I think the best solution should be as follow:
1) USer select records in a grid control in a original form and then push a button.
2) The selected records appears in a new form in a grid like the previous form.
3) There is no necessary to copy any information, just used standard filters in AX by displaying the data.
My possible solution is:
1) Use Args Class to move the information over?
2) It'a more than one options to filter out the information, like you have mentioned, what is the most practical way because no copy need to be done - just standard filter?
You have to use Args class, that's the only practical way. But you can pass different things in Args, such as a record or an object parameter.There is no one best approach, it depends on your requirements and limitations, as I discussed above. I thought that a temporary table would make sense for your requirement "additional textboxes who is used to override fields on the table when user press on OK button in the new form", but I can't decide it for you, because I don't have enough information.
The only thing that I'm confused with at the moment is what parameters should I met when I ONLY want to marked records in the first form to be displayed in the second form?
Take a look at this example where you have code that iterates over selected records and running custom logic:
Alternatively, you can look at CustInvoiceJour (AX4/AX2009) or CustInvoiceJournal (AX2012) and look at the clicked method for SendXMLOriginal.
As I wrote in my first answer, use the MultiSelectionHelper class. It's easy to use, because it hides some implementation details:
MultiSelectionHelper helper = MultiSelectionHelper::construct();
// do the work
True. The MultiSelectionHelper would work like charm for this! :-)
Hi Martin thanks for the answer.
The Procedure is as follow:
1) User press a button on a Form1 after he select records in the Grid1
2) Another form open: Form2 and new grid control exist Grid2
3) In the Property of the Grid2 a DataSource is selected who is the same as Grid1 in the previous form.
4) Grid2 only display selected records from Grid1
-Where should I then put this code?
on the Click() Method in the button?
Use filter() Method in the Grid2?
The only thing that Im trying to think is that method will run on Grid2 when the Form2 open.
I got this code Martin, but where should I place the code, and how can I be sure that specific control will display the records?
Sorry, I have no idea which strategy are you implementing. Let's start from the end: How do you want to restrict the query in the new form? By a filter? If so, add a new range(s) in datasource's init() and use IDs of the records selected in the original form.
Don't overthink this, Sandri.
Use tables for persisting data structures. If you use tables temporarily, you will have to decide if you want to clean them up manually, or learn how to use temporary tables and keep them in scope of your code while executing your logic.
Use forms for interface and presentation, and try limit the logic to the bare minimum.
Use classes to perform tasks, like copy data from A to B.
Sure, you can write an essay of code in a clicked method on a button on a form, but it is really not good application design, and you end up with something hard to maintain in the long run.
If you use MorphX the right way, it will work in favor of what you are trying to achieve. Adding a form with a grid with a filter is quick and easy. You can easily select rows in a grid.
You can the utilize a class that takes selections and do "something" with them.
Finally you can present the result in a different form.
How I want to restrict my query in a new form?
I want to restricted by selected records from the previous form - CheckboxSelected = YES
So I add a Method in a datasources in the form that display the records by overwriting the init() method?
Hello thanks for the answer
I just need to use standard filter function, at least it was requested.
So, filter() method on the current Grid that display the selected records is the most practical way or what?