Transferfields command using with multiple linked tables

Hi all,

I have to copy record from a tableA of CompanyA into same tableA of companyB.

I am using command TRANSFERFIELDS so that record of tableA from companyA is transferred into the tableB of companyB - this works as expected.
I need to add also tableB which is basically a linked table to tableA, but I can’t workout how to link another table to the source table. I tried to crate a local function of CU50011 and PAGEn from where I run below code which is inside a CU50011.

This is the code and transferres record into the selected company as expected:
JobTaskRec.CHANGECOMPANY(CompanyTo); //copy record in another company
JobTaskRec.TRANSFERFIELDS(SourceJobTask); //user’s record to be copied
JobTaskRec.INSERT(TRUE);

And, now I need to copy also records of linked tableB and I am lost on linking records from TableA to TableB.

Can you advice me how to link table to source table so that I can transfer also records of linked table, too?

Thank you
Damjan

Sorry, but I lost the idea for the TableB. I can see “I am using command TRANSFERFIELDS so that record of tableA from companyA is transferred into the tableB of companyB” and can read “I need to add also tableB which is basically a linked table to tableA”. You need to select information for the TRANSFERFIELDS either from tableA or tableB.

Hi, I have copy record from tableA and also linked record on tableB.

I hope it’s understandable, now.

Tnx

Sorry, but I don’t understand because I can see TableB 2 time => you need to select 1 table for the TRANSFERFIELDS and transfer “manually” for 2nd table

hi RedFoxUA,

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


There were 1 blank record in the line table, and I deleted it, but still the error pops.

Can you advice me on what else to check?

Thank you

BR Damjan

Hi,

just to update. Work as expected, I re-run the test and works as expected.

Thank you

it is good that your code works and it is OK

P.S. 1 small remark - I can see you use different (JobToRec.TRANSFERFIELDS(SourceJob) and TargetJobTaskF.TRANSFERFIELDS(SourceJobTaskF,FALSE) ), but not the same record (table) like you wrote before

Hi,

It is the same, I renamed it to more meaningful name.

Thanks

it is not the same for code - you use “another instance”