How to loop through selected rows

GaryDGaryD 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!

Comments

  • SavatageSavatage Member Posts: 7,142
    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

    Code
    REPEAT
          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 click
    OnPush()
    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->Until
  • jreynoldsjreynolds Member Posts: 175
    Check out the SETSELECTIONFILTER function.
  • GaryDGaryD Member Posts: 66
    JReynolds, this is exactly what I needed. Worked perfectly. Thanks a million!
  • GaryDGaryD Member Posts: 66
    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?
  • garakgarak Member Posts: 3,263
    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!
Sign In or Register to comment.