Rename Fnction within a repeat loop
Steve
Member Posts: 81
Hello All,
I tried to rename mulitple records within a repeat loop and it seems to rename the first record and then breaks the loop. Any ideas?
Code below:
Lines.SETRANGE("Document No.",MasterNo);
IF Lines.FIND('-') THEN
REPEAT
Lines.RENAME(MasterNo,Lines."Line No.");
UNTIL Lines.NEXT=0;
I tried to rename mulitple records within a repeat loop and it seems to rename the first record and then breaks the loop. Any ideas?
Code below:
Lines.SETRANGE("Document No.",MasterNo);
IF Lines.FIND('-') THEN
REPEAT
Lines.RENAME(MasterNo,Lines."Line No.");
UNTIL Lines.NEXT=0;
Steve
0
Comments
-
Steve wrote:Hello All,
I tried to rename mulitple records within a repeat loop and it seems to rename the first record and then breaks the loop. Any ideas?
Code below:
Lines.SETRANGE("Document No.",MasterNo);
IF Lines.FIND('-') THEN
REPEAT
Lines.RENAME(MasterNo,Lines."Line No.");
UNTIL Lines.NEXT=0;
When you rename, you change order of records and it is possible, that the newly renamed record is last in recordset.
why not use RENAMEALL?
regards
BostjanL0 -
or define a second record variable which you use in the repeat loop to rename the record
...
repeat
rec2 := rec1;
rec2.RENAME(...);
until ..next = 0;0 -
Is RENAMEALL vaild? I get an error when I tried it.
Thanks everyone.
After i wrote the help posting, I tried the second rec var approach and it works OK.
Thanks
AgainSteve0 -
As far as i know, a RENAMEALL doesn't exist in the C/AL environment.
You even get an error stating "unkown variable".
:-k ](*,)Now, let's see what we can see.
...
Everybody on-line.
...
Looking good!0 -
RENAMEALL not exist... :whistle:
If you are browsing (looping) through some table and want modify something, use separate variable (as written) for the change... it is only solution for that to not lost the position in the loop and if you are on MS SQL, only solution for good performance... Same for DELETE...0 -
You need to create a new variable and call rename on that.
Lines.SETRANGE("Document No.",MasterNo);
IF Lines.FIND('-') THEN
REPEAT
Lines2.get(Lines."Document No.",Lines."Line No.");
Lines2.RENAME(MasterNo,Lines."Line No.");
UNTIL Lines.NEXT=0;0 -
kine wrote:RENAMEALL not exist... :whistle:
If you are browsing (looping) through some table and want modify something, use separate variable (as written) for the change... it is only solution for that to not lost the position in the loop and if you are on MS SQL, only solution for good performance... Same for DELETE...
Mea culpa! :oops:
I post that post way to early on Monday morning,..
BostjanL0 -
-
I changed my to to the following.
Hdr.SETCURRENTKEY("Document Type","No.");
IF Hdr.FIND('-') THEN
REPEAT
CLEAR(THdr);
THdr.GET(Hdr."Document Type",Hdr."No.");
THdr.RENAME(Hdr."Document Type",Hdr."No." + COPYSTR(COMPANYNAME,1,1));
UNTIL Hdr.NEXT=0;
Var.
Name DataType Subtype Length
Hdr Record Sales Header
THdr Record Sales Header
This just append the first letter of the Copany Name to the end on the current no. so SO-01112 becmes SO-01112C in the Cronus company.
THE WEIRD PART.
This will work for amster tables ( Customer, Item, Vendor) BUT NOT for Sales header, Purchase Header, etc....
Test if you like, but i am stumped..... ](*,)Steve0 -
SOLVED....
By putting a letter to the end of a code field the newly renamed record would fall below the current record by the default sort. So this would casue the repeat loop to keep grabbing the just renamed record.
Thanks All =D>Steve0 -
it is why is better to use otherrecord for rename and have the original set filtered for record you want to rename (which have for example no last char added or something...)0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

