Get customer or prospects in Dynamics AX 2012

谁说我不能喝 提交于 2019-12-11 13:25:03

问题


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.

  1. Make two queries (translate to appropriate properties yourself):

  2. Query1:

    select * from dirPartyTable
        exists join custTable
        where custTable.Party == dirPartyTable.RecId
    
  3. Query2:

    select * from dirPartyTable
        exists join smmBusRelTable
        where smmBusRelTable.Party == dirPartyTable.RecId;
    
  4. Make two views (View1 and View2) based on the queries.

  5. Make a union query (Query3), see how to Combine Data Sources in a Union Query, remember to specify the UnionType (Union or UnianAll).

  6. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!