Retrieving data from another company
NAV can hold data for many companies under your corporate umbrella. Many times, users will want consolidated reports that show them data from all of the companies in the system. This recipe will show you how to retrieve that data from anywhere in the system.
Getting ready
Make sure you have at least two companies in your database like Cronus USA and Cronus Canada.
How to do it...
Create a new codeunit from Object Designer.
Add the following global variables:
Name
Type
Subtype
Customer
Record
Customer
Company
Record
Company
Add the following code to the
OnRun
trigger of the codeunit:IF Company.FINDSET THEN REPEAT Customer.CHANGECOMPANY(Company.Name); MESSAGE('Company Name: %1\Customer Count: %2', Company.Name,Customer.COUNT); UNTIL Company.NEXT = 0;
Save and close the codeunit.
When you run the codeunit you will see a window like the one shown in the following screenshot:
How it works...
In order to get data from another company within NAV, we have to...