Hello.
I'm creating a page with an action button to open a window that shows posted shipment headers to pick some of them and insert them in a table.
The structure is: page->action button->run codeuntit->call to a page that shows headers->pick some lines->call back to codeunit-> call to insert lines.
I have the problem in the callback from modal page (headers) to codeunit, because in the codeunit I get all the rows, not the selected rows.
In my headers page I have:
CurrPage.SETSELECTIONFILTER(Rec);
MESSAGE('Qty: ' + FORMAT(Rec.COUNT)); // I get the right number of selected rows for example 2
MyCodeunit.CreateLines(Rec);
After, in MyCodeunit, in CreateLines funtcion, I receive all the lines, not the selected lines. If I check the COUNT again it counts all the lines. I thought Rec sends to the codeunit only selected lines. Is this correct? What can be the problem?
Page source table is "Sales Shipment Header". Codeunit variable is a record of "Sales Shipment Header".
All the best!
0
Answers
I have never actually tried this, but I do not see any reason why this would not work. Please check for any CLEAR, CLEARALL, and RESET that might purge the filter set by SETSELECTIONFILTER. Also make sure you do not mess with MARKEDONLY. SETSELECTIONFILTER sets this as it needs to be.
And finally, make sure you pass the record using VAR parameters wherever you pass Rec on into any functions.
I've created a test codeunit and page to check where is the problem:
Codeunit 50005 "Cod. Customer Test"
Page 50000 "Customer Test" -> works with Customer table.
Here is the code:
Page:
OnQueryClosePage(CloseAction : Action None) : Boolean
If CloseAction IN [ACTION::OK,ACTION::LookupOK] THEN
CreateLines; // Function in the page
CreateLines()
CurrPage.SETSELECTIONFILTER(Rec);
MESSAGE('Total recs: ' + FORMAT(Rec.COUNT));
CodeunitCustomerTest.CreateLines(Rec); // type Codeunit subtype 50005
Codeunit:
OnRun()
CustomersWindow.LOOKUPMODE := TRUE; // type page subtype 50000
IF CustomersWindow.RUNMODAL <> ACTION::Cancel THEN;
CreateLines(Customers2 : Record Customer)
MESSAGE('Qty: ' + FORMAT(Customers2.COUNT));
Ok, after I run the codeunit, it opens page 50000 listing my customers. I select for example 3. The message in the Page shows Qty=3, but after the call to CreateLines in the codeunit, the message shows que quantity of customers, for example 650.
I don't know why the codeunit call does not send the selected recs. Is it a VAR parameter problem? Any ideas?
Pffffffffff, the problem was the VAR parameter as you told me. I had not clicked VAR in the local definition of the function parameter!
Thank you!
The VAR should do the trick..
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!