问题
I am trying to get customer or prospect using X++ and use it on a lookup.
There is a method in the DirPartyTable
that returns what I want.
DirPartyTable::isCustomerOrRelation
while select * from dirPartyTable
{
if(DirPartyTable::isCustomerOrRelation(dirPartyTable.RecId))
{
//Get the Name
//info(dirPartyTable.Name);
}
}
But when I build a query to the lookup I am trying to pass the DirPartyTable::isCustomerOrRelation(dirPartyTable.RecId)
on the addRange
of the query somehow.
Is there a way to do it or is it impossible ?
回答1:
If you go to the source of isCustomerOrRelation
(and isCustomer
and isRelation
) you see, that the method returns true if a customer or prospect exists in the current company.
Your while select
, while correct, is inefficient, because it may have to scan a million parties to select on thousand customers or prospects present in you current company.
A more efficient, but syntactical illegal, while select
would be:
while select * from dirPartyTable
exists join custTable
where custTable.Party == dirPartyTable.RecId
union
select * from dirPartyTable
exists join smmBusRelTable
where smmBusRelTable.Party == dirPartyTable.RecId;
{
info(dirPartyTable.Name);
}
While illegal in X++ it is possible using queries and views.
Make two queries (translate to appropriate properties yourself):
Query1:
select * from dirPartyTable exists join custTable where custTable.Party == dirPartyTable.RecId
Query2:
select * from dirPartyTable exists join smmBusRelTable where smmBusRelTable.Party == dirPartyTable.RecId;
Make two views (View1 and View2) based on the queries.
Make a union query (Query3), see how to Combine Data Sources in a Union Query, remember to specify the
UnionType
(Union
orUnianAll
).Make a view based on the Query3, see how to Create a View Based on a Query.
Result, select all records using X++:
while select * from dirPartyCustOrRelationTable
{
info(dirPartyCustOrRelationTable.Name);
}
Or you can use the Query3 directly to retrieve the records.
来源:https://stackoverflow.com/questions/11118100/get-customer-or-prospects-in-dynamics-ax-2012