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 BTable 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 FromField2=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
The Page "Copy Project" should have 2 global variables for the Globals and linked to fields:Field1=Company From (E.g. CompanyFrom)Field2=Company To (e.g. CompanyTo)
The codeunit "Copy Job" should have the same 2 Global variables and procedure like
SetFromToCompanies(CompanyFrom2: Code, CompanyTo2: Code) // to be honest I don't remember the light for Company field
CompanyFrom := CompanyFrom2;
CompanyTo := CompanyTo2;
And before CopyJobCompany..Run you need to write the function CopyJobCompany.SetFromToCompanies(CompanyFrom,CompanyTo)
P.S. Why do you use the CASE-function for same operations?
P.P.S. it is good to have the Clear(CopyJobCompany) before you use Run
I was able to resolve my issue with your assistance.I have added 2 identical Global Variables = CompanyFrom (text, 50) and CompanyTo (text, 50) on Page and Codeunit and then on both objects also function SetFromToCompanies to fill both global variables from that page into the CU.I have redesigned my code to transfer complete record from table A of companyFrom to table A of CompanyTo, and removed CASE sentance, since I do not need it, now.I will have to add linked tables of project to be transferred at the same time as the project is being transferred.
Thank you, Damjan