How to write to other company with CHANGECOMPANY function

tankh008tankh008 Member Posts: 26
edited 2010-06-28 in Navision Attain
Can anyone tell me how I can write to a table of another company within the same database using CHANGECOMPANY function? I enter code like below but the record is create in the SAME company instead of another company... ](*,)

>>>>>>>>>>>>
CHANGECOMPANY(fmrline1."Transfer to Company");
genline1.SETRANGE(genline1."Journal Batch Name",'ASSETS');
genline1.SETRANGE(genline1."Journal Batch Name",'FA');
IF genline1.FIND('+') THEN BEGIN
genline1."Journal Template Name":='ASSETS';
genline1."Journal Batch Name":='FA';
genline1."Line No.":=genline1."Line No."+10000;
genline1.INSERT;
genline1.VALIDATE(genline1."Account Type",genline1."Account Type"::"Fixed Asset");
genline1.VALIDATE(genline1."Account No.",fmrline1."No.");
genline1."Posting Date":=TODAY;
genline1."Document Date":=fmrline1."Document Date";
FA.GET(fmrline1."No.");
genline1."FA Posting Date":=TODAY;
genline1."Posting Group":=FA."FA Posting Group";
genline1."Document No.":=fmrline1."Document No.";
genline1."Source Code":='FAGLJNL';
genline1.VALIDATE(genline1."Source Type",genline1."Source Type"::"Fixed Asset");
genline1."Source No.":=fmrline1."No.";
FAPG.GET(FA."FA Posting Group");
genline1.VALIDATE(genline1."Bal. Account No.",FAPG."Acquisition Cost Account");
genline1.VALIDATE(genline1.Amount,fmrline.Amount);
genline1.MODIFY;

Comments

  • DaveTDaveT Member Posts: 1,039
    Hi,

    You need cal the CHANGECOMPANY for each record variable used.

    e.g.
    genline1.CHANGECOMPANY(fmrline1."Transfer to Company");

    You also need to be careful of validates if they are looking at sub tables e.g. dimensions.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    All record variables that are used within a Validate-Trigger aren't changed to the other company. In the majority of those cases CHANGECOMPANY won't work. Perhaps you can create a table and store some information into it in the target company that will initialize a process in the target company for what you want to do.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • kinekine Member Posts: 12,562
    I recommend to not use CHANGECOMPANY to write into another company if you want to write into common tables and not some special tables created for this purpose. To process the writes correctly, you need to run the processing in the second company to keep the correct business logic. As already described, write only some data you need to pass and run process over these data in the second company e.g. through NAS and JOBQUEUE or own process...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • WaldoWaldo Member Posts: 3,412
    Indeed, validates don't work when doing this..

    Just look at the InterCompany functionality. That's why it's all processed using inbox/outbox journals .. en when logged in in the right company, you can process the inbox.. having the validation rules for that company.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • tankh008tankh008 Member Posts: 26
    I see. Thanks for all the suggestion and useful information. I will tried the intercompany approach. Thanks!
  • WaldoWaldo Member Posts: 3,412
    You're welcome 8)

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
Sign In or Register to comment.