我在CRM Dynamics 2013中有一个场景,我需要删除数千条记录,基本上我有联系人,帐户,潜在客户,我需要基本上从所有者'待删除'的联系人中删除所有营销列表,以便这些联系人没有收到列表,我想知道哪种方法最好,我可能如果我创建一个使用RemoveMemberListRequest的程序,一切都很好但我如何使用基本上说的sdk指定查询,从列表中删除成员列表中的联系人将所有者设置为“待删除”。
我看到这种方法有点担心,因为我计划使用RemoveMemberListRequest,它寻找EntityId(联系人)的guid和ListID(营销列表)的guid,问题是有很多列表和很多符合此条件的联系人。重要的标准是关注联系人与所有者是待删除,这意味着我没有特定的方法来查询添加联系人的特定营销列表,将待处理删除作为自己的字段。我希望这是有道理的,任何帮助都会受到赞赏。
请查看我到目前为止的内容
public static Entity GetConatctWithPendingDeletion(IOrganizationService service)
{
QueryExpression qe = new QueryExpression();
qe.EntityName = "contact";
qe.ColumnSet = new ColumnSet("fullname", "ownerid", "parentcustomerid", "new_title");
qe.Criteria.AddCondition("ownerid", ConditionOperator.Equal, "0F040671-1E83-E111-83B9-D067E5EBE694");// tbhis represents the optionset 'Pending Deletion'
EntityCollection response = service.RetrieveMultiple(qe);
return response.Entities[0];
Console.WriteLine(response.Entities.Count());
Console.ReadLine();
RemoveMemberListRequest req = new RemoveMemberListRequest();
req.EntityId = new Guid("xxxxxxx-xxx-xxx-xxx-xxxxxxx");//how do I specifty a list of Contact guids based on above code
req.ListId = new Guid("xxxxxxx-xxxx-xxxx-xxxxx");// Also here , how do I specify the lists I want,
RemoveMemberListResponse resp = (RemoveMemberListResponse)service.Execute(req);
}
答案 0 :(得分:0)
您应该能够通过JOIN
营销列表成员关系实体与您的帐户/联系人/潜在客户查询解决此问题并迭代生成的记录:
QueryExpression qe = new QueryExpression();
qe.EntityName = "contact";
qe.ColumnSet = new ColumnSet("fullname", "ownerid", "parentcustomerid", "new_title");
qe.Criteria.AddCondition("ownerid", ConditionOperator.Equal, "0F040671-1E83-E111-83B9-D067E5EBE694");
LinkEntity le = new LinkEntity();
le.EntityAlias = "lm"; // note the alias, you need it when accessing fields of the linked entity
le.Columns = new ColumnSet("listid");
le.JoinOperator = JoinOperator.Inner;
le.LinkFromEntityName = "contact";
le.LinkFromAttributeName = "contactid";
le.LinkToEntityName = "listmember";
le.LinkToAttributeName = "entityid";
eq.LinkEntities.Add(le);
EntityCollection response = service.RetrieveMultiple(qe);
// iterate over list members
foreach (var listmember in response.Entities)
{
RemoveMemberListRequest req = new RemoveMemberListRequest();
req.EntityId = listmember.Id;
// the linked (relationship) entity fields are of type AliasedValue
AliasedValue av = listmember.GetAttributeValue<AliasedValue>("lm.listid");
EntityReference lm = (EntityReference)av.Value;
req.ListId = lm.Id;
RemoveMemberListResponse resp = (RemoveMemberListResponse)service.Execute(req);
}