Microsoft CRM 4.0 LINQ - 使用 LINQ 从 CRM 获取属性显示名称

发布于 2024-11-16 11:07:07 字数 378 浏览 2 评论 0原文

有人使用 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>

提前致谢

Has anyone done this with the Xrm Advanced Dev Extension? I am creating an external portal

Let's say I have an attribute in the account entity called aaa_accountfield. The account entity XML has

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

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空宴 2024-11-23 11:07:07

不确定它与 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;

        }

Not sure what it has to do with XML but I'm pretty sure you can use the ADX to get an IOrganizationService which should be able to make metadata requests. I would give the following code a shot. You should probably modify it to check whether the different languages return values before grabbing the first or you will be susceptible to exceptions.

 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;

        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文