开发者

RetrieveDuplicatesRequest for Dynamic Entity

开发者 https://www.devze.com 2023-03-30 05:21 出处:网络
Need advice, I am retrieving GUID for the duplicate Records for a customise entity that i have created.However code that i research and found is using CRM business Entity:

Need advice, I am retrieving GUID for the duplicate Records for a customise entity that i have created.However code that i research and found is using CRM business Entity:

RetrieveDuplicates开发者_运维百科Request request = new RetrieveDuplicatesRequest();
request.BusinessEntity = lead;
request.MatchingEntityName = EntityName.lead.ToString();
request.PagingInfo = new PagingInfo();

could anyone provide me the link or help for dynamic entity?

Thanks


The first thing to check is that your custom entity has duplicate detection enabled in the customize entity screen. If it doesn't, turn it on and publish the entity, then move on to this code from the SDK. This code will search for a duplicate account based on the account name.

// 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);

If you want to use a dynamic entity with the above code, just instantiate a dynamic entity instead of the lines that make an account, and set 'ReturnDynamicEntities' to true on the Request object. If you were looking for a way to start searching the entire database for duplicates rather than asking if a specific record is a duplicate, here is the code:

// 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;

This is using the BulkDetectDyplicates message. This should get you headed on the right path.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号