How to loop only the selected records in a page?

In Dynamics NAV 2018, I'm trying to loop through my selected records in a page and change the column "App" to TRUE in all selected records when clicking button "Incluir en APP":

enter image description here

What I've been trying so far is:

    Rec.App := TRUE;
UNTIL Rec.Next := 0;

But that will modify all displayed records and not all selected.

Also tested without CurrPage.SETSELECTIONFILTER(Rec); but made no difference.

How can I loop only the selected records?


  • First, The parameter in SETSELECTIONFILTER should not be Rec. It can be, but shouldn't. Because this function will put filter in the variable passed as the parameter. So in your case after your code is done your page should end up being filtered only to selected records (using marks). Of course you can reset filter on rec after all, but this will reset user filters (that might have been previously applied) as well. You don't want to mess with that. So just use another variable of the same type.

    Second, your code doesn't work (probably) because you didn't do findset after SETSELECTIONFILTER. Or should work otherwise if there are no other things about this page that you forgot to mention (like if it is temporary table). But keep in mind first point.

    Third, the best way to code this would be

        Rec1.App := TRUE;
    UNTIL Rec1.Next := 0;