Retrieving data from other companies
NAV can hold data for many companies under your corporate umbrella. Often, users will request consolidated reports that show them the 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.
How to do it...
Create a new codeunit with Object Designer.
Add the following global variables:
Name
Type
Subtype
Customer
Record
Customer
Company
Record
Company
Write the following code into 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.
On executing the codeunit, you should see a window similar to the one in the following screenshot; the number of message screens displayed depends on the number of companies available...