Crosscompany Keyword in select statement in D365 F&O - X++ Code

Rumman Ansari   Software Engineer   2023-05-25   718 Share
☰ Table of Contents

Table of Content:


Crosscompany Keyword in select statement in D365 F&O - X++ Code

Select Project properties

Crosscompany Keyword in select statement in D365 F&O - X++ Code

NMFA Company is selected.

Crosscompany Keyword in select statement in D365 F&O - X++ Code

NMFA Company is selected. Now open table browser and see data.

Crosscompany Keyword in select statement in D365 F&O - X++ Code

Remove NMFA Company which is already selected. Now make it blank blank and save it.

Crosscompany Keyword in select statement in D365 F&O

Now open table browser and see data.

Crosscompany Keyword in select statement in D365 F&O - X++ Code

class JoinExampleClass
{
   /// <summary>
   /// Class entry point. The system will call this method when a designated menu 
   /// is selected or when execution starts and this class is set as the startup class.
   /// </summary>
   /// <param name = "_args">The specified arguments.</param>
   public static void main(Args _args)
   {
       EmployeeTable emp;  
       while select emp
        {
          Info(strFmt("%1 %2", emp. EmpId, emp. EmpName));
        }
   }
 
}

If you will remove company name from the project you will get default result of company.

Crosscompany Keyword in select statement in D365 F&O - X++ Code

If you want to take result from some specific set of company use container and the keyword crosscompany.


class JoinExampleClass
{
   /// <summary>
   /// Class entry point. The system will call this method when a designated menu 
   /// is selected or when execution starts and this class is set as the startup class.
   /// </summary>
   /// <param name = "_args">The specified arguments.</param>
   public static void main(Args _args)
   {
       EmployeeTable emp; 
       container con= ["INMF", "DAT"];

       while select crosscompany: con emp
        {
          Info(strFmt("%1 %2", emp. EmpId, emp. EmpName));
        }
   }
 
}

Above code will return result from ["INMF", "DAT"] company only.

Crosscompany Keyword in select statement in D365 F&O

If you don't want specific company you just select crosscompany keyword, It will select data from all companies.


class JoinExampleClass
{
   /// <summary>
   /// Class entry point. The system will call this method when a designated menu 
   /// is selected or when execution starts and this class is set as the startup class.
   /// </summary>
   /// <param name = "_args">The specified arguments.</param>
   public static void main(Args _args)
   {
       EmployeeTable emp; 
       // container con= ["INMF", "DAT"];

       while select crosscompany  emp
        {
          Info(strFmt("%1 %2", emp. EmpId, emp. EmpName));
        }
   }
 
}