Problem using RecordRef and Changecompany

Tbi
Member Posts: 33
Hi.
I am trying to copy a lot of tables from one company to another using RecordRef. But it seems that the OPEN method doesn't work as planned.
This is the code I am trying to execute, (I have set filter on just one table here to test..)
rTables is of record 2000000028 with information about tables.
I always get the error that the post already exists, but the Company2 is empty. So does anyone have an idea what I am doing wrong here?
Tbi.
I am trying to copy a lot of tables from one company to another using RecordRef. But it seems that the OPEN method doesn't work as planned.
This is the code I am trying to execute, (I have set filter on just one table here to test..)
rTables is of record 2000000028 with information about tables.
sOldCompany := 'Company1'; sNewCompany := 'Company2'; CLEAR(rTables); rTables.SETRANGE("Tabellnr.", 3); rTables.FIND('-'); REPEAT CLEAR(rrRecordRef); rrRecordRef.OPEN(rTables."Tabellnr."); rrRecordRef.FIND('-'); REPEAT CLEAR(rrRecordRefNC); rrRecordRefNC.OPEN(rTables."Tabellnr.", FALSE, sNewCompany); rrRecordRefNC.INIT; rrRecordRefNC := rrRecordRef.DUPLICATE; rrRecordRefNC.INSERT; //Gets an error here... rrRecordRefNC.CLOSE; UNTIL rrRecordRef.NEXT = 0; rrRecordRef.CLOSE; UNTIL rTables.NEXT = 0;
I always get the error that the post already exists, but the Company2 is empty. So does anyone have an idea what I am doing wrong here?
Tbi.
1
Answers
-
The DUPLICATE, copies the source-variable to the destination-variable, but in THE SAME COMPANY. This is what creates the error.
You have to copy the fields 1 by 1.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!1 -
Thanks for fast reply.
Now I have added some code to loop trough the fields in the table and copying the values, but it still gives me the same error..
Am I missing something here?sOldCompany := 'Company1'; sNewCompany := 'Company2'; CLEAR(rTables); rTables.SETRANGE("Tabellnr.", 3); rTables.FIND('-'); REPEAT CLEAR(rrRecordRef); rrRecordRef.OPEN(rTables."Tabellnr."); rrRecordRef.FIND('-'); REPEAT CLEAR(rrRecordRefNC); rrRecordRefNC.OPEN(rTables."Tabellnr.", FALSE, sNewCompany); rFields.SETRANGE(rFields.TableNo, rTables."Tabellnr."); rFields.FIND('-'); rrRecordRefNC.INIT; //Loops trough fields.. REPEAT CLEAR(frFieldRef); frFieldRef := rrRecordRefNC.FIELD(rFields."No."); frFieldRef.VALUE := rrRecordRef.FIELD(rFields."No.").VALUE; UNTIL rFields.NEXT = 0; rrRecordRefNC.INSERT; //Gets an error here... rrRecordRefNC.CLOSE; UNTIL rrRecordRef.NEXT = 0; rrRecordRef.CLOSE; UNTIL rTables.NEXT = 0;
1 -
I found the problem....
I had forgotten to set a filter on Companyname on rTables, so it tried to insert into the same table more than once.. :whistle:
So I just added the line:rTables.SETRANGE(rTables.Selskapsnavn, sOldCompany);
And then it works correct..
- Tbi1 -
Thanks Tbi and kriki.
I was also trying to migrate data from one company to another using RecordReference but I wasn't succeeding, I even used the DUPLICATE function but then I couldn't move forward, but now I did. Thanks!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions