2011-08-22 55 views
0

需要幫助,我檢索GUID的重複記錄的自定義實體,我有created.However代碼,我的研究,發現使用CRM的商業實體:RetrieveDuplicatesRequest動態實體

RetrieveDuplicatesRequest request = new RetrieveDuplicatesRequest(); 
request.BusinessEntity = lead; 
request.MatchingEntityName = EntityName.lead.ToString(); 
request.PagingInfo = new PagingInfo(); 

任何人都可以提供我的動態實體的鏈接或幫助?

感謝

+0

您是否必須使用動態實體?如果您引用其類,則您的自定義實體仍爲業務實體... – devin

回答

1

要檢查的第一件事是,你的自定義實體在自定義實體屏幕啓用重複檢測。如果沒有,請打開它併發布實體,然後從SDK中轉到此代碼。此代碼將根據帳戶名稱搜索重複帳戶。

// Set up the CRM service. 
CrmAuthenticationToken token = new CrmAuthenticationToken(); 
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle"; 

CrmService service = new CrmService(); 
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx"; 
service.CrmAuthenticationTokenValue = token; 
service.Credentials = System.Net.CredentialCache.DefaultCredentials; 

// Create the account instance and set the name property. 
account acct = new account(); 
acct.name = "Microsoft"; 

// Create the request object. 
RetrieveDuplicatesRequest Request = new RetrieveDuplicatesRequest(); 
Request.BusinessEntity = acct; 
Request.MatchingEntityName = EntityName.account.ToString(); 
Request.PagingInfo = new PagingInfo(); 

// Execute the request. 
RetrieveDuplicatesResponse Response = 
    (RetrieveDuplicatesResponse) Service.Execute(Request); 

如果你想用一個動態的實體與上面的代碼,只是實例化一個動態的實體,而不是使一個帳戶的線路,並設置「ReturnDynamicEntities」真Request對象上。如果你正在尋找一種方式來開始搜索整個數據庫的副本,而不是詢問特定的記錄是重複的,這裏是代碼:

// Set up the CRM Service. 
CrmAuthenticationToken token = new CrmAuthenticationToken(); 
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active  Directory authentication. 
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle"; 

CrmService service = new CrmService(); 
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx"; 
service.CrmAuthenticationTokenValue = token; 
service.Credentials = System.Net.CredentialCache.DefaultCredentials; 

// Create a query expression for the bulk duplicate detection. 
QueryExpression query = new QueryExpression(); 
query.EntityName = EntityName.account.ToString(); 

// Create the request (do not send an e-mail). 
BulkDetectDuplicatesRequest request = new BulkDetectDuplicatesRequest(); 
request.JobName = "Detect Duplicate Accounts"; 
request.Query = query; 
request.RecurrencePattern = string.Empty; 
request.RecurrenceStartTime = new CrmDateTime(); 
request.RecurrenceStartTime.Value = DateTime.Now.ToString("s"); 
request.SendEmailNotification = false; 
request.ToRecipients = new Guid[0]; 
request.CCRecipients = new Guid[0]; 
request.TemplateId = Guid.Empty; 

// Execute the request. 
BulkDetectDuplicatesResponse response = (BulkDetectDuplicatesResponse)service.Execute( request); 
Guid jobId = response.JobId; 

這是使用BulkDetectDyplicates消息。這應該讓你走上正確的道路。