Copy record using transferfields with records of linked table

Damjan
Member Posts: 94
Hi All,
I need a some advice on how to link a table to a source table from the one I have to copy record. Source table has some records in a linked table and I would like to copy also these records of the linked table.
code:
CopyJobTasks.CopyProjectTasks -> this is the function I would call after recors in the main table=JobTaskRec are inserted.
I was looking at CU80, but it does not work on that way, or let me say, that I would really like to have as little code inserted as possible, since we are going to migrate to BC and I do now want to have a lot of work with migration:)
Thanks Damjan
I need a some advice on how to link a table to a source table from the one I have to copy record. Source table has some records in a linked table and I would like to copy also these records of the linked table.
code:
JobTaskRec.CHANGECOMPANY(CompanyTo); //copy record in another company JobTaskRec.TRANSFERFIELDS(SourceJobTask); //user's record to be copied JobTaskRec.INSERT(TRUE);
CopyJobTasks.CopyProjectTasks -> this is the function I would call after recors in the main table=JobTaskRec are inserted.
I was looking at CU80, but it does not work on that way, or let me say, that I would really like to have as little code inserted as possible, since we are going to migrate to BC and I do now want to have a lot of work with migration:)
Thanks Damjan
0
Best Answer
-
I have now resolved all the issues, except this one.
In the codeunit this code is inserted on OnRun trigger:
//Transfers a record of Job (always only 1 record). This is header table
JobToRec.CHANGECOMPANY(CompanyTo);
JobToRec.TRANSFERFIELDS(SourceJob);
JobToRec.INSERT(TRUE);
//Finds all records of linked table to header table. SlourcJobTaskF is linked table
SourceJobTaskF.SETRANGE("Job No.",SourceJob."No."); //SourceJob is header table
IF SourceJobTaskF.FINDSET THEN
REPEAT
TargetJobTaskF.INIT;
TargetJobTaskF.CHANGECOMPANY(CompanyTo);
TargetJobTaskF.TRANSFERFIELDS(SourceJobTaskF,FALSE);
TargetJobTaskF.INSERT;
UNTIL SourceJobTaskF.NEXT = 0;
This means that SourceTable is the header table with only 1 records of the job (project) and in lines of the project (job) there are 3 records (entries).
Code sets the range to those 3 records as expected, but when all 3 recrods are transferred I get an error:
Microsoft Dynamics NAV
The Job Task already exists. Identification fields and values: Job No.='',Job Task No.=''
OK
SOLUTION: Deleted blank record in source table.0
Answers
-
I have now resolved all the issues, except this one.
In the codeunit this code is inserted on OnRun trigger:
//Transfers a record of Job (always only 1 record). This is header table
JobToRec.CHANGECOMPANY(CompanyTo);
JobToRec.TRANSFERFIELDS(SourceJob);
JobToRec.INSERT(TRUE);
//Finds all records of linked table to header table. SlourcJobTaskF is linked table
SourceJobTaskF.SETRANGE("Job No.",SourceJob."No."); //SourceJob is header table
IF SourceJobTaskF.FINDSET THEN
REPEAT
TargetJobTaskF.INIT;
TargetJobTaskF.CHANGECOMPANY(CompanyTo);
TargetJobTaskF.TRANSFERFIELDS(SourceJobTaskF,FALSE);
TargetJobTaskF.INSERT;
UNTIL SourceJobTaskF.NEXT = 0;
This means that SourceTable is the header table with only 1 records of the job (project) and in lines of the project (job) there are 3 records (entries).
Code sets the range to those 3 records as expected, but when all 3 recrods are transferred I get an error:
Microsoft Dynamics NAV
The Job Task already exists. Identification fields and values: Job No.='',Job Task No.=''
OK
SOLUTION: Deleted blank record in source table.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