Copy records from table to same table of another company

Hi All,

Business Case: As project manager I would like to copy already created project on company A to company B.

Purposed solution: Create page to specify project and company where to copy that project to. User can select a project and a company to copy the project to. It cannot be copied to same company where project already exists (added control/error message). 

I have created a page "Copy Project" and codeunit "Copy Project".

Technical design:
Table Job has inserted record in company A -> project is always copied from HQ company A, but it might changes in the future to be able to copy from any company (for now, not).
Table Job in company B can have some records since some projects can already exists, so I will just insert new record from company A, but first will check if any record of same number series value exists and if it does then an error message pops, if not, then new record is going to be inserted in table Job in company B
Table A of company C - same goes for company C (we have 8 companies in database)

Page "Copy Project"
Globals: CopyJobCU | datatype=codeunit | subtype=50000 (this is the ID of codeunit I use to call it on this page)
Page fields:
Field1=Company From
Field2=Company To
- both fields are linked to source table ID 20000006 = Company
- user selects a value from dropdown list (data are read from T20000006)

On trigger: OnQueryClosePage I have added the code to call the codeunit:

IF CloseAction IN [ACTION::OK,ACTION::LookupOK] THEN BEGIN
ValidateUserInput;
CopyJobCompany.RUN;
Message(Text001);
END;

In onRun trigger of codeunit "Copy Job" I have added code


IF CopyJob."Company To" <>'' THEN BEGIN
CompanyTo := CopyJob."Company To";
CASE CompanyTo OF
CompanyTo::'WKA' :
BEGIN
JobTo.CHANGECOMPANY('WKA')
JobTo.TRANSFERFIELDS(JobFrom) //whole record - will change to required fields
JobTo.INSERT(TRUE);
END;
CompanyTo::'WKB':
BEGIN
JobTo.CHANGECOMPANY('WKB')
JobTo.TRANSFERFIELDS(JobFrom)
JobTo.INSERT(TRUE);
END;
ComapnyTo::'WKC' :
BEGIN
JobTo.CHANGECOMPANY('WKC')
JobTo.TRANSFERFIELDS(JobFrom)
JobTo.INSERT(TRUE);
END;
END;

My issue is that I cannot figure out how to get selected value from fields: "Company From" and "Company To" where user selected them on page, and I need to past them on Codeunit as a variable so I can filter per "CompanyTo" inside the codeunit.

I think I should use local variable, but it does not work since I have added this:
local function=Copy which has local variable=CompanyToCopy | DataType=Page | Subtype=Copy Project

Thanks for any suggestions, Damjan

Related
Recommended