cross company lookup

Hi

I have a lookup which displays records from other company(not the current company).

But when I select the value am getting the following error : The value in the field is not found in the relating table".

I think it is checking for the value selected n the current company.But it should check in the the other company from which the record is displayed.

Can anyone help me on this please?

Hi Sindhu,

If this is the case, you can use the ‘CrossCompany’ keyword in your query.

Below example would help you creating your cross company related query:

Custtable ct;

Query q;

QueryRun qr;

QueryBuildDataSource qbds ;

;

q = new query();

qbds = q.addDataSource(tablenum(CustTable));

q.allowCrossCompany(true);

q.addCompanyRange(‘axt’);

q.addCompanyRange(‘dat’);

qr = new QueryRun(q);

while(qr.next())

{

ct = qr.get(tablenum(CustTable));

info(ct.AccountNum);

}

Thanks,

Vishal Tiwari

If your table is company-specific and there is a relation to validate, AX correctly validates the value. It’s the same as if you type in a value - if it doesn’t exist in the current company, AX prevents you from breaking data consistency. It’s irrelevant that the value would be correct in another company.

Hi Vishal,

I was using the above code in my Queries.But still I am getting that error.Though am using the crossCompany in my code it is validating for that value in the current company.

Regards

Sindhu

Hi Martin,

I have checked it and my table is not company specific one.

Regards

Sindhu

The key is in the relation. Define a composite relation that will use DataAreaId and the field you’re interested in, so AX will know from which company is should take data. Be sure that no other relation is used (typically there is a relation on EDT that you don’t want to use).

If you do it right, even the lookup will work automatically.

Hi Martin,

How can we do this? I couldn’t understand. This is my table:

Company

CustAccount

User should first select company and select CustAccount from related company.

Hi Metin,

Try the Below link

http://waytoax.wordpress.com/2013/10/13/lookup-value-from-multiple-companies/

Hi Sadullah,

I just did already same like yours, but I would like to do this with just create a relation and don’t supress validate method so I just curious about Martin’s solution.

@metin: What I meant was creating two fields: one with EDT SelectableDataArea and one with CustVendAC or something (not CustAccount - the relation defined there seems to be used even if IngoreEDTRelation is set to Yes). Then you would create a new table relation pointing to DataAreaId and AccountNum fields of CustTable. The lookup for customer account would be then filtered by data area ID.

It works (tested in AX2012), but not so well as it should. The lookup shows right values when selecting an account for the first time, but if you want to change it later, the lookup seems to include some values from the current company. I’m not going to investigate that further.

Thank you… :slight_smile:

I tried with Ax 2009 and seem works well. Thank you… :slight_smile:

Hi,

I tried with as per suggestion, but still i am not getting the lookup based on Company Id.

I created the new normal relation

Please help me

Hi, I tried with as per suggestion, but still i am not getting the lookup based on Company Id.