How to add the Cross company for the AOT Query?

Hi All,

I want to add cross company for the AOT Query.

I have tried below code but while runing getting error like “Stack trace: Invalid company argument for cross company query.”

Please suggest me how to add the cross company for the “AOT Query” in Ax 2012

cannot see your code.

See this documentation,…/cc518738.aspx

Hi kranthi,

I am not able to show record in the form grid according the lookup selection.

I have string control lookup.

I have written a lookup in the form string control.

please see the below code.

public void lookup()

Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
FieldId NameField;

SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(CompanyInfo), this);

sysTableLookup.addLookupField(fieldNum(CompanyInfo, Name));

queryBuildDataSource = query.addDataSource(tableNum(CompanyInfo));

NameField = fieldNum(CompanyInfo, Name);



I have used temp table to show the record to the form gird.

Please see the below code.

i have created a class and created below code in this method,this class return the temp record
to the modfied method in the form lookup string control

public void initInventMinMax(Str 50 _LegalEntityLookup)
InventTable inventTable,invntTable;
InventSum inventSum;
PurchReqLine purchReqLine;
InventItemInventSetup inventItemInventSetup;
EcoResProductCategory ecoResProductCategory;
QueryRun queryRun;
container legalentitycon;
Query query;
str 50 legalentitystr;
CompanyInfo CompanyInfo;
QueryBuildDataSource qbds1,qbds2;

select DataArea from companyInfo where companyInfo.Name == _LegalEntityLookup ;
legalentitystr =companyInfo.DataArea;
legalentitycon = str2con(companyInfo.DataArea);
query = new query();
qbds1 = query.addDataSource(tableNum(inventTable));
qbds2 = qbds1.addDataSource(tableNum(inventSum));
queryRun = new queryRun(query);

inventTable = queryRun.get(tableNum(inventTable));
inventSum = queryRun.get(tableNum(inventSum));

select crossCompany:legalentitycon sum(PurchQty)
from purchReqLine
group by purchReqLine.ItemId
where purchReqLine.ItemId == inventTable.ItemId
&& purchReqLine.BuyingLegalEntity == CompanyInfo::findDataArea(legalentitystr).RecId
&& (purchReqLine.RequisitionStatus == PurchReqRequisitionStatus::Draft
|| purchReqLine.RequisitionStatus == PurchReqRequisitionStatus::InReview);

select crossCompany:legalentitycon LowestQty,HighestQty
from inventItemInventSetup
where inventItemInventSetup.itemid == inventTable.ItemId
&& inventItemInventSetup.Override == NoYes::Yes;

select crossCompany:legalentitycon RecId
from ecoResProductCategory
join invntTable
where invntTable.Product == ecoResProductCategory.Product
&& invntTable.ItemId == inventTable.ItemId;

if(((inventSum.availPhysicalCalculated() + inventSum.orderedSum() + purchReqLine.PurchQty) <
InventItemInventSetup.LowestQty) && ecoResProductCategory.RecId)
this.insert_InventMinMax(inventTable, inventSum, inventItemInventSetup.LowestQty,
inventItemInventSetup.HighestQty, purchReqLine.PurchQty); // this method is to insert the
record in to the temp table.

form method

public InventMinMax initInventMinMax()
autoGeneratePurchReq = new AutoGeneratePurchRequisition();

return autoGeneratePurchReq.parmInventMinMax();

form lookup control modified field

public boolean modified()
boolean ret;

ret = super();


return ret;

please suggest me to show the temp table record to the form grid

Your code contains several cross-company queries. Please tell us which line of code is throwing the error. Then we can focus on the relevant part (and ignore code not related to the problem).

Also, please use Insert > Insert code to past source code next time. It preserves indentation and therefore it makes code much more readable.