Cross Company queries - X++
When we create a query in X++, it fetches record only for
the company that we are logged in. If we want to get records for multiple
companies, we have the keyword in X++. i.e. crossCompany.
Select query:
For example,
Let’s say we write the following query.
SalesTable salesTable;
Let’s say we write the following query.
SalesTable salesTable;
while select * from salesTable
{
info(strfmt(“%1”,salesTable.SalesId));
}
{
info(strfmt(“%1”,salesTable.SalesId));
}
It will return only the records from the company we are
logged into. Now we want to get records from all companies. We will need to write
following query.
while select crossCompany
salesTable
{
info(strfmt(“%1”,salesTable.SalesId));
}
{
info(strfmt(“%1”,salesTable.SalesId));
}
This crossCompany keyword will return all the companies record. If we want to get
specific companies records, we need to use container.
For example,
container specificComp = [‘USMF’,’USMR’];
container specificComp = [‘USMF’,’USMR’];
while select crossCompany : specificComp salesTable
{
info(strfmt(“%1”,salesTable.SalesId));
}
It will return all companies record that are specified in
container.
AOT query:
Same scenarios with the AOT query. Lets say we want only
logged in company data. We simply create an AOT query. But if we want to fetch
records for multiple companies then we need to set a property in query. i.e. AllowCrossCompany = Yes.
Run the query, it will prompt a query filter box
which contains an option for Company
range.
You can select multiple or single company to fetch records
accordingly.
Comments
Post a Comment