[英]Is there a quick way to view all associated records in MS Dynamics CRM?
有时我需要删除CRM中具有关联的重复记录。 在这些情况下,我必须重新分配这些关联。 相关实体菜单使我可以一个一个地检查记录是否在与其相关的任何实体中都有关联。 这迫使我浏览许多相关实体。 有没有一种更快的方法来查看记录的所有关联?
您可以制作一个新的记录表单,将所有相关记录显示为单个页面上的子网格-可以节省一些单击次数。
使用这种方法的几点注意事项:
不是通过CRM UI,而是如果您是SQL向导,则可能想出一些精美的查询来做到这一点。 然后,如果您想更进一步,则可以通过单击来部署SSRS报告。
如果您要处理诸如联系人或客户之类的OOB记录,则还应考虑针对这种情况的OOB合并-因为这将自动为您重新创建子记录(当然,它将所有子记录重新添加到新的“主”记录中,但这通常是预期的功能,因此在大多数情况下都可以使用)。
如果您需要重新分配所有关联,则可以这样做:
您只是克隆了一条记录,新记录将具有旧记录的所有关联。
所有N:1关系都可以通过在SQL中查询实体的筛选视图来找到,但是最快的解决方案是按照建议使用CRM内置的合并功能。 它不会删除重复项,但会取消激活它,并将您指定的所有内容分配给“主”记录。 从那里,您可以删除停用的记录。
我知道这个问题很旧,但是我创建了一个控制台应用程序,它将显示相关的GUID和关联记录的逻辑名称。 目前不适用于多对多关系,因为我的应用程序不需要它。 可以很容易地显示链接到记录,但这不是我所需要的。
static void Main(string[] args)
{
IOrganizationService OrganizationService = null;
string sourceBaseUrl = "http://server/org";
OrganizationService = CrmHelpers.GetService(sourceBaseUrl);
//OrganizationService = CrmHelpers.GetService("sock-devcrm2015", "acs-training", "80", "http", "username", "password", "domain");
//query for relationships for the desired record
//need to get GUID and LogicalName
Entity get = new Entity();
Console.WriteLine(string.Format("What is the Logical Name?"));
Console.Write("String: ");
get.LogicalName = Console.ReadLine();
Console.WriteLine(string.Format("What is the GUID?"));
Console.Write("GUID: ");
get.Id = Guid.Parse(Console.ReadLine());
RetrieveEntityRequest retrieveEntity = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Relationships,
LogicalName = get.LogicalName
};
RetrieveEntityResponse response = (RetrieveEntityResponse)OrganizationService.Execute(retrieveEntity);
var oneToN = response.EntityMetadata.OneToManyRelationships;
var nToOne = response.EntityMetadata.ManyToOneRelationships;
foreach (var relationship in oneToN)
{
string fetch = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='" + relationship.ReferencingEntity + @"'>
<filter type='and'>
<condition attribute='" + relationship.ReferencingAttribute + @"' operator='eq' value='" + get.Id.ToString() + @"' />
</filter>
</entity>
</fetch>";
var results = OrganizationService.RetrieveMultiple(new FetchExpression(fetch));
foreach (var result in results.Entities)
{
Console.WriteLine(string.Format("1:N || GUID: {0} LogicalName: {1}", result.Id, result.LogicalName));
}
}
Console.WriteLine("----------------------------------------------------------");
Console.WriteLine("----------------------------------------------------------");
foreach (var relationship in nToOne)
{
string fetch = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='" + relationship.ReferencedEntity + @"'>
<link-entity name='"+relationship.ReferencingEntity+ @"' from='"+relationship.ReferencingAttribute+@"' to='"+relationship.ReferencedAttribute+@"' alias='a'>
<filter type='and'>
<condition attribute='" + get.LogicalName+ @"id' operator='eq' value='" + get.Id.ToString() + @"' />
</filter>
</link-entity>
</entity>
</fetch>";
var results = OrganizationService.RetrieveMultiple(new FetchExpression(fetch));
foreach (var result in results.Entities)
{
Console.WriteLine(string.Format("N:1 || GUID: {0} LogicalName: {1}", result.Id, result.LogicalName));
}
}
Console.Write("END");
Console.ReadLine();
}
class CrmHelpers
{
public static IOrganizationService GetService(string baseUrl)
{
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = CredentialCache.DefaultCredentials.GetCredential(new Uri(baseUrl), "negotiate");
Uri endpoint = new Uri(string.Format("{0}/XRMServices/2011/Organization.svc", baseUrl));
OrganizationServiceProxy service = new OrganizationServiceProxy(endpoint, null, credentials, null);
service.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
return service;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.