Prefixe:='FCM'; SalesInvoiceHeader.RESET; SalesInvoiceHeader.SETRANGE("Posting Date",DateFilter,WORKDATE); IF SalesInvoiceHeader.FINDSET THEN BEGIN REPEAT SalesInvoiceHeader.RENAME(Prefixe+ COPYSTR(SalesInvoiceHeader."No.",3,STRLEN(SalesInvoiceHeader."No."))); UNTIL (SalesInvoiceHeader.NEXT = 0); END;The problem is that the code doesn't loop, it modifies only one record.
Comments
You're trying to rename "Sales Invoice Header" with a PK field ("No."). [-X
Try to change your current key to sort documents without PK or use a temporary table to do that (renaming).
Can you explain a little more?
IF SalesInvoiceHeader.FINDSET(TRUE, TRUE) THEN BEGIN
Maybe you will go away without understanding what amazan has written before
Yes, you should do that but it's not the whole solution. You need to use a different record variable for the rename than you are using for the looping. Accomplish this by usign 1 record variable for the looping. Then, as you retreived each record, copy it to a second variable and do the rename.
Yes, I can.
You're trying to rename a bunch of invoices using Primary Key (field "No.") so when you're in renaming records, the position of the cursor changes depending of new value of your documents,.
For example:
First Loop
Invoice 'A' <- Cursor (Invoices 'A' becomes to 'FRZA')
Invoice 'B'
Invoice 'C'
After renaming
Invoice 'B'
Invoice 'C'
Invoice 'FRZA' <- Cursor
Next step it will be "end of loop" because the position of the cursor is the end of the selected records and can't find another record to do RENAME.
so, what shall I do to correct it?
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
What shall I do?
What about adding a filter on No.?
Please test it in TEST Environment.
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
That's what I did with my second code...
I used one variable for loop (SalesInvoiceHeader) and then inside the loop, I used a second variable (SalesInvoiceHeader1.GET(SalesInvoiceHeader."No.")) to do the rename....
Correct me if I am wrong :-k
But, you are about to rename posted invoices and modify entries. It is quite likely that what you try to do is illegal, or at the least, not good practice.
error should be from inside functions within the loop. Please check in debugger.
This will change all ur records.
Mind you, this will not change any records. This *might* lead to your code successfully doing what you want *for a particular data set* you're processing, but this is no general solution.
You're right, it wouldn't. The issue is your renamed records fall with in the filter range. One approach would be to initially mark the records you need to change and then only process those marked records.
2 - loop through the temporary records.
3 - for each temporary record, GET the corresponding 'real' record and RENAME that record as necessary
RIS Plus, LLC
I think the problem is the "Posting Date" did not found the filter record you use with DateFilter variable and WORKDATE,
since "Posting Date" is Date type only.
RIS Plus, LLC
And MODIFYALL does not require any retrieval statement. No GET, FIND, FINDSET, etc is needed before a MODIFYALL or DELETEALL.
first, your filter not run correctly, test it with count function to check how many record you get.
There's something wrong with your DateFilter, except all the codes, everything looks fine..
When you want to modify records in a loop, you need to take care that you do not skip any records nor re-process any that you processed already. The problem is most prevalent with RENAME, but not restricted to it.
Skipping may occur, when you modify the data of the record variable on which you call NEXT (or FIND('>'). These same circumstances may also lead to reprocessing, depending on the nature of the change to the variable.
Reprocessing may additionally occur if the modified record is placed somewhere in the set of records to be processed at a position after the current one.
Different kind of methods can be applied in order to prevent the problems.
Probably the most robust is the one suggested by DenSter: create a temporary list of records to be processed which you do not modify during procession. Changing the sorting order or applying suitable filters might be others, depending on circumstances.
While FINDSET(TRUE,TRUE) appears to be a solution, it is not. The parameters are meant to optimize calls to the database server, not to solve the problem discussed here.