Thursday, March 2, 2023

CrossCompany and changeCompany using x++.

 CrossCompany and changeCompany using x++.


 CrossCompany:

    Required company filter:

    MyTable 	myTable; 
    container 	conCompanies = ['cmp1', 'cmp2', 'cmp3'];

    while select crossCompany : conCompanies * from myTable
    {
	// code
    }

    All company filters:

    MyTable 	myTable; 

    while select crossCompany * from myTable
    {
        changeCompany(myTable.dataAreaId)
     {
            // code             myTable.update() or myTable.delete() or myTable.insert();         }     }

  

  Applying On Dynamic queries:

    Query 			query = new Query();
    QueryRun 			queryRun;
    QueryBuildDataSource 	qBDS;

    qBDS = query.addDataSource(TableNum(CustTable));
	
    // Way-1 (we can add required company)
    query.allowCrossCompany(true);
    query.addCompanyRange('cmp1');
    query.addCompanyRange('cmp2');

    // Way-2 (It will loop all companies)
    queryRun = new QueryRun(query);
    queryRun.allowCrossCompany(true);


Change Company:

    MyTable 	myTable; 
    changeCompany('cmp1') { while select myTable { // code } }


Ref : Link


Keep Daxing!!

No comments:

Post a Comment