Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Using GET in WHILE cycle to modify record

(1) ShareShare
ReportReport
Posted on by 46

He there!

Some days ago my colleague suggested to GET a record in WHILE construction to modify this record which is on the cycle, for example instead of this construction:

IF MyRec.FINDSET(TRUE) THEN REPAT
  MyRec.Value := Value1;
  MyRec.MODIFY;

UNTIL MyRec.NEXT = 0;


she suggested to use the following construction:

IF MyRec.FINDSET THEN REPAT
  MyRec2.GET(MyRec.KeyValue);
  MyRec2.Value := Value1;
  MyRec2.MODIFY;

UNTIL MyRec.NEXT = 0;

I see this not reasonable. Are there cases when we really do this way?

We use 2009 R2 but the qustion is opened for upper RTC versions as well.

Help to understand the issue please.

*This post is locked for comments

  • Vlad_K Profile Picture
    Vlad_K 10 on at
    RE: Using GET in WHILE cycle to modify record

    Hi

    This is absolutely reasonable general approach.

    What if you have a set of setranges and setfilters before the loop. What if what you're changing is making the record not match the filters anymore. NEXT is the case here.

    Look how NEXT works. It is looking on a current record you're on and based on the key and filters, gets the next record. But when the record has just become out of filters, then NEXT is simply unpredictable. This was pointed in numerous discussions.

    Considering how often just a simple loop suddenly gets additional filters, it is strongly recommended to use another rec variable to modify the record. This is a general recommendation allowing you to avoid problems in future and making you to refactor a little less code.

    But technically speaking, as Hannes said, it could work fine for the cases when you modify a field that is not filtered.

  • Verified answer
    Hannes Holst Profile Picture
    Hannes Holst 5,767 on at
    RE: Using GET in WHILE cycle to modify record

    Hi,

    Depends on the filter and the data you want to modify.

    When modifying a value within the filter, I would use another record-instance.

    Otherwise it is not necessary.

    See the two Examples here which highlight the difference: docs.microsoft.com/.../findset-function--record-

    Additionally, consider to use MODIFYALL for certain situations.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans