Reputation: 699
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":
What I've been trying so far is:
CurrPage.SETSELECTIONFILTER(Rec);
REPEAT
Rec.App := TRUE;
Rec.MODIFY;
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?
Upvotes: 0
Views: 3394
Reputation: 36
We can remove the need to use a looping statement by using the "Modify All" Method and change all the App Boolean field for all filtered records at once, just to improve code readability and efficiency
//set the filter for records
CurrPage.SETSELECTIONFILTER(Rec1);
//check if records available
IF Rec1.Findset THEN
Rec1.ModifyAll(App, True);
And done this will modify all your selected records in one go! Learn More
https://learn.microsoft.com/en-us/previous-versions/dynamicsnav-2018-developer/MODIFYALL-Function--Record-
Upvotes: 1
Reputation: 2334
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
CurrPage.SETSELECTIONFILTER(Rec1);
Rec1.Findset;
REPEAT
Rec1.App := TRUE;
Rec1.MODIFY;
UNTIL Rec1.Next := 0;
Currpage.update(false);
Upvotes: 2