Change Company in Code
![[Mike_B]](https://we.vanillicon.com/eae8109ec3d4d5ca17ec40bce12dff08_100.png)
[Mike_B]
Member Posts: 15
We have 40 companies in the database and adding all the time. Is it possible to write a report to go through each company and change the posting date (From and To) by running a single report?
I have written some code but the draw back is that I have to hard code to Company Name? Is there a way to do it without hard coding the Company Names?
"General Ledger Setup".CHANGECOMPANY('CRONUS UK Ltd.');
VALIDATE("Allow Posting From",vAllowPostinFrom);
VALIDATE("Allow Posting To","vAllow PostingTo");
MODIFY;
"General Ledger Setup".CHANGECOMPANY('CRONUS UK Ltd 2');
VALIDATE("Allow Posting From",vAllowPostinFrom);
VALIDATE("Allow Posting To","vAllow PostingTo");
MODIFY;
Regards
Mike
I have written some code but the draw back is that I have to hard code to Company Name? Is there a way to do it without hard coding the Company Names?
"General Ledger Setup".CHANGECOMPANY('CRONUS UK Ltd.');
VALIDATE("Allow Posting From",vAllowPostinFrom);
VALIDATE("Allow Posting To","vAllow PostingTo");
MODIFY;
"General Ledger Setup".CHANGECOMPANY('CRONUS UK Ltd 2');
VALIDATE("Allow Posting From",vAllowPostinFrom);
VALIDATE("Allow Posting To","vAllow PostingTo");
MODIFY;
Regards
Mike
0
Answers
-
Hey Mike.
There is a way. System table called Company exists and it only consists of field Name in which it stores name of company. To see how it looks like create a new form with table Company and make a list and do a preview.
Hope it helps!0 -
U can use the table COMPANY.
So, make a loop:Company.findset; repeat GLSetup.CHANGECOMPANY(Company.Name); GLSetup.VALIDATE("Allow Posting From",vAllowPostinFrom); GLSetup.VALIDATE("Allow Posting To","vAllow PostingTo"); GLSetup.MODIFY; until Company.next = 0;
But be carefull with validates if you use changecompany. If in the onvalidate trigger is also code that change a other table, these records in the other table will be changed on the company from where the report is running.
RegardsDo you make it right, it works too!0 -
Thanks Garak
Works really well0 -
garak wrote:
Company.findset; repeat GLSetup.CHANGECOMPANY(Company.Name); GLSetup.VALIDATE("Allow Posting From",vAllowPostinFrom);
Just assign those values, and if you need to run any of the validation logic, then you recreate that in your report. If there is no code in OnValidate of those fields, then nothing is lost. If there IS code in there, then all it takes to screw up this process is for someone to put in logic that uses a record variable.
DO.... NOT.... USE.... VALIDATE.... WHEN.... USING.... CHANGECOMPANY!!!
There, did it anyway :whistle:0 -
I have taken all advice and removed the Validates.0
-
@Daniel: For this case i wrote:But be carefull with validates if you use changecompany. If in the onvalidate trigger is also code which change a other table, these records in the other table will be changed in the company from where the report is running.
The source was only copy&paste (forgotten to remove the validate, thats right).Do you make it right, it works too!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