How to write to other company with CHANGECOMPANY function

tankh008
Member Posts: 26
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;
>>>>>>>>>>>>
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;
0
Comments
-
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.0 -
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."0
-
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...0
-
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.0 -
I see. Thanks for all the suggestion and useful information. I will tried the intercompany approach. Thanks!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