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;
Steve
0
Comments
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
BostjanL
...
repeat
rec2 := rec1;
rec2.RENAME(...);
until ..next = 0;
Thanks everyone.
After i wrote the help posting, I tried the second rec var approach and it works OK.
Thanks
Again
You even get an error stating "unkown variable".
:-k ](*,)
...
Everybody on-line.
...
Looking good!
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...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
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;
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Mea culpa! :oops:
I post that post way to early on Monday morning,..
BostjanL
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
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..... ](*,)
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>
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.