How to loop through selected rows

GaryD
Member Posts: 66
A user opens a list form and selects (highlights) multiple records. In C/AL, how can I loop through those selected records, performing 'X' action against each record. I'm being asked to provide the Mark (CTRL+F1) functionality using a button on the form. CTRL+F1 will update every record highlighted but so far in C/AL, I can only update the one record that I'm currently on. I just need to know how to move through all selected records. Thanks in advance!
0
Comments
-
For example, something like when you go to Apply-Entries in payments.
If you select a number of inv/credit to apply and hit F9 all the selected lines have their Apply-to ID filled in. You mean like that?
Try it, run the code coverage to see how that works
CodeREPEAT VendLedgEntry.TESTFIELD(Open,TRUE); VendLedgEntry."Applies-to ID" := VendEntryApplID; VendLedgEntry.MODIFY; UNTIL VendLedgEntry.NEXT = 0;
Another example ...
I have a button on my sales header that clear sales info on 1 clickOnPush() IF NOT DIALOG.CONFIRM(Question,TRUE) THEN EXIT ELSE SalesLine.RESET; SalesLine.SETRANGE("Document Type","Document Type"); SalesLine.SETRANGE("Document No.","No."); IF SalesLine.FIND('-') THEN REPEAT IF SalesLine."Special Order Purchase No." <> '' THEN CLEAR(SalesLine."Special Order Purchase No."); CLEAR(SalesLine."Special Order Purch. Line No."); SalesLine.MODIFY(TRUE); UNTIL SalesLine.NEXT = 0;
Your key here is Repeat->Until0 -
Check out the SETSELECTIONFILTER function.0
-
JReynolds, this is exactly what I needed. Worked perfectly. Thanks a million!0
-
jreynolds, you're reply got me much closer but I have another sticking point. I got the SetSelectionFilter working in that I created a record variable, applied the SetSelectionFilter function, and I can loop through the filtered records (in the temporary table). But what I need to do now is take each one of those filtered records and MARK the same rows in the displayed list. Can you provide any help on that?0
-
But don't forget. When using setselectionfilter or markedonly(true) and you have a lot of entries and only marked some records, its an bad performance on SQL Server. Better: Make an function (Button save / delete) to store the records in an TempTab and then work with the records in TempTab.
Or use the same function like when you go to Apply-Entries in payments.Do you make it right, it works too!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions