2016-04-25 3 views
1

У меня есть программа, которая вытаскивает счета-фактуры из нашей системы CRM Dynamics Online в CSV-файл.FetchXML Filter out Duplicate Values ​​

Иногда наши продавцы создают несколько счетов-фактур в одном и том же заказе в CRM, и мне нужен способ удалить любые дублированные счета-фактуры на .csv.

Хотелось бы только выставлять счета с четкими номерами заказов. Как это будет достигнуто? Я работаю все утро с отличными результатами безрезультатно.

Мой код:

private EntityCollection GetInvoices(Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy crmService) 
    { 
     string fx = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'> 
       <entity name='invoice'> 
        <attribute name='invoiceid' alias='InvoiceId' /> 
        <attribute name='customerid' alias='ShipTO' /> 
        <attribute name='shipto_postalcode' alias='ShipZip' /> 
        <attribute name='shipto_line2' alias='ShipAddr2' /> 
        <attribute name='shipto_line1' alias='ShipAddr1' /> 
        <attribute name='shipto_stateorprovince' alias='ShipState' /> 
        <attribute name='shipto_country' alias='ShipCountry' /> 
        <attribute name='shipto_city' alias='ShipCity' /> 
        <attribute name='neu_customerponumber' alias='PO' /> 
        <attribute name='paymenttermscode' alias='Terms' /> 
        <attribute name='createdon' alias='ShipDate'/> 
        <attribute name='ordernumber' alias='InvoiceNo' /> 
          "; 
     fx += GetInvoiceFilter(); 
     fx += @" 
        <link-entity name='salesorder' from='salesorderid' to='salesorderid' visible='false' link-type='outer' alias='order1'> 
         <attribute name='datefulfilled' alias='FirstOfShippingDate' /> 
         <link-entity name='systemuser' from='systemuserid' to='ownerid' visible='false' link-type='outer' alias='systemuser1'> 
          <attribute name='fullname' alias='SalesRep' /> 
         </link-entity> 
        </link-entity> 
        <link-entity name='invoicedetail' from='invoiceid' to='invoiceid' visible='false' link-type='outer' alias='invoicedetail1'> 
         <attribute name='neu_percentdiscount' alias='Discount' /> 
         <attribute name='invoicedetailid' alias='InvoiceDetailId' /> 
         <attribute name='baseamount' alias='Amount' /> 
         <attribute name='extendedamount' alias='Sales' /> 
         <link-entity name='product' from='productid' to='productid' visible='false' link-type='outer' alias='product1'> 
          <attribute name='neu_division' alias='Division' /> 
          <attribute name='producttypecode' alias='Desc' /> 
          <attribute name='productnumber' alias='CatalogNumber' /> 
         </link-entity> 
        </link-entity> 
        <link-entity name='account' alias='account1' to='customerid' from='accountid'> 
         <attribute name='accountnumber' alias='CustID' /> 
        </link-entity> 
       </entity> 
       </fetch>"; 

     return crmService.RetrieveMultiple(new FetchExpression(fx)); 


    } 



    private string GetInvoiceFilter() 
    { 
     string fetchFilter = ""; 

     fetchFilter = @"<filter type='and'>"; 

     if (txtOrderName.Text.Length > 0) 
     { 
      fetchFilter += @"<condition attribute='ordernumber' operator='eq' value='"; 
      fetchFilter += txtOrderName.Text; 
      fetchFilter += "' />"; 
     } 
     else 
     { 
      fetchFilter += @"<condition attribute='statuscode' operator='eq' value='1' />";    
      fetchFilter += @"<condition attribute='neu_exportedtopeachtree' operator='null' />"; 
      fetchFilter += @"<condition attribute='createdon' operator='on-or-after' value='"; 
      fetchFilter += dtpFrom.Text; 
      fetchFilter += "' />"; 
      fetchFilter += " <condition attribute='createdon' operator='on-or-before' value='"; 
      fetchFilter += dtpTo.Text; 
      fetchFilter += "' />"; 
     } 

     fetchFilter += @"</filter>"; 

     return fetchFilter; 
    } 

ответ

1

Четкое положение на выборки заявления только отфильтровывает повторяющиеся идентификаторы, которые возвращаются в наборе результатов. Чтобы отфильтровать наши обманки на основе номера заказа, вам придется делать это программно после того, как результаты вернутся.

+0

Ahh, что имеет смысл, спасибо! –

Смежные вопросы