web
You’re offline. This is a read only version of the page.
close
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 48

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

I have the same question (0)
  • Verified answer
    Hannes Holst Profile Picture
    5,767 on at

    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.

  • Vlad_K Profile Picture
    10 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans