需要建议,我正在为我创建的自定义实体检索重复记录的GUID。但是我研究和发现的代码是使用CRM业务实体:
RetrieveDuplicatesRequest request = new RetrieveDuplicatesRequest();
request.BusinessEntity = lead;
request.MatchingEntityName = EntityName.lead.ToString();
request.PagingInfo = new PagingInfo();
有人能为我提供动态实体的链接或帮助吗?
谢谢
答案 0 :(得分: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);
如果要使用具有上述代码的动态实体,只需实例化动态实体而不是创建帐户的行,并在Request对象上将“ReturnDynamicEntities”设置为true。如果您正在寻找一种方法来开始在整个数据库中搜索重复数据,而不是询问特定记录是否重复,则代码如下:
// 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消息。这应该让你走上正确的道路。