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 ?
If you go to the source of
isCustomerOrRelation
(andisCustomer
andisRelation
) 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 illegal in X++ it is possible using queries and views.
Make two queries (translate to appropriate properties yourself):
Query1:
Query2:
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++:
Or you can use the Query3 directly to retrieve the records.