【问题标题】:Microsoft CRM 4.0 LINQ - Getting attribute displaynames from CRM with LINQMicrosoft CRM 4.0 LINQ - 使用 LINQ 从 CRM 获取属性显示名称
【发布时间】:2011-06-20 18:54:38
【问题描述】:

有人用 Xrm Advanced Dev Extension 做过这个吗?我正在创建一个外部门户

假设我在帐户实体中有一个名为 aaa_accountfield 的属性。帐户实体 XML 具有

<displaynames>
 <displayname description="attribute display name" languagecode="1033" />
 <displayname description="attribute display name in some other language" languagecode="1045" />
</displaynames>

提前致谢

【问题讨论】:

    标签: xml linq dynamics-crm-4


    【解决方案1】:

    不确定它与 XML 有什么关系,但我很确定您可以使用 ADX 获取 IOrganizationService,它应该能够发出元数据请求。我会给下面的代码一个镜头。您可能应该修改它以在获取第一个之前检查不同语言是否返回值,否则您将容易受到异常的影响。

     var crm = new Xrm.XrmDataContext("CacheDisabled");
     crm.UsingService(service =>
            {
                    // Use this code to grab a complete set of EntityMetadata.
                    var entityRequest = new RetrieveEntityRequest();
                    entityRequest.LogicalName = "account";
                    entityRequest.RetrieveAsIfPublished = false;
    
                    RetrieveEntityResponse entityResponse = new RetrieveEntityResponse();
                    EntityMetadata entityMetadata = entityResponse.EntityMetadata;
                    //entityMetadata.Attributes...
    
                    // Use this to grab AttributeMetadata for a specific attribute.
                    RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest();
                    attributeRequest.EntityLogicalName = "account";
                    attributeRequest.LogicalName = "name";
                    attributeRequest.RetrieveAsIfPublished = false;
    
                    RetrieveAttributeResponse attributeResponse = new RetrieveAttributeResponse();
                    AttributeMetadata attributeMetadata = attributeResponse.AttributeMetadata;
                    string labelLanguage1 = attributeMetadata.DisplayName.LocLabels.Where(l => l.LanguageCode.Value == 1033).First().Label;
                    string labelLanguage2 = attributeMetadata.DisplayName.LocLabels.Where(l => l.LanguageCode.Value == 1045).First().Label;
    
            }
    

    【讨论】:

    • 谢谢科尔,我会试试看!
    • 我刚刚意识到这是 CRM 2011。对 CRM 4.0 有任何想法吗?
    • 没关系,我明白了 - 无论如何谢谢 :) 我很适合 2011 年,然后当我们升级时
    • 不,这是 CRM 4.0 代码,CRM SDK 版本 4.0.12 添加了高级开发人员扩展。 CRM 2011 代码与此类似。我想既然你在标题中提到了“高级开发者扩展”,那么你一定是在谈论这个......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多