Sunday, December 3, 2023

Change Compney And Cross Company in X++

 

change company:-

If you're working on one company within your code but need to insert data into another company, you'd indeed utilize the ChangeCompany functionality.
This feature in Dynamics AX or Dynamics 365 Finance and Operations allows you to switch the context within your code to another company for specific operations.


Code:-

   public static void main(Args _args)

   {

       CustTable           Cust;

       changecompany("DAT")

       {

       ttsBegin;

        Cust.AccountNum = "AE-000001";

       Cust.insert();

       ttsCommit;

       }

   }

CrossCompany:-

You can fetch data from tables across companies using CrossCompany keyword in X++ select queries.

You can also use containers to fetch data from subset of companies.

For example:-

public static void main(Args _args)

   {

       VendTable vendTable;

       ;

       While Select CrossCompany * from vendTable

       {

           info(Strfmt("%1 : %2", vendTable.AccountNum, vendTable.dataAreaId));

       }

   }


public static void main(Args _args)

   {

       VendTable vendTable;

       container con;

       ;

       con = ["USMF","DAT","uspi" ];

       While Select CrossCompany : Con * from vendTable

       {

           Info(Strfmt("%1 : %2", vendTable.AccountNum, vendTable.dataAreaId));

       }

   }









No comments:

Post a Comment

My Requirement is Delete option in Vendor Master for all roles except System Administrator

   [FormControlEventHandler(formControlStr(VendParameters, VendParameters_YNV_VendorMasterDeletionOption), FormControlEventType::Modified)] ...