使用 CRM 4.0 Web 服务设置 BusinessEntity 选择列表值

发布于 2024-08-12 03:06:10 字数 416 浏览 2 评论 0原文

我正在尝试在 CRM 4.0 中创建一个 ImportMap 对象。我需要设置 TargetEntity 属性,它是一个选项列表值。 链接文本 似乎暗示可以通过使用来完成,

importmap map = new importmap();
map.name = "test map";
map.targetentity = new Picklist();
map.targetentity.name = "Contact"

但这似乎总是将目标实体属性保留为空。

有什么想法吗?

I'm trying to create an ImportMap object in CRM 4.0. I need to set the TargetEntity property which is a Picklist value. link text seems to imply that it can be done by using

importmap map = new importmap();
map.name = "test map";
map.targetentity = new Picklist();
map.targetentity.name = "Contact"

but this always seems to leave the target entity property as null.

Any thoughts?

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

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

发布评论

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

评论(2

捂风挽笑 2024-08-19 03:06:10

如果它是一个选择列表,您将必须提供索引值。假设您有一个名为 TargetValues.Contact 的枚举,其值为 1,那么它会像:

map.targetentity = new Picklist();
//map.targetentity.name = "Contact"
map.targetentity.Value = Convert.ToInt32(TargetEntities.Contact);

-- 编辑 --

我相信对于您想要实现的目标,您将必须以某种方式检索目标实体,只有这样您才能来列举它们。

查看此内容,可能会有所帮助。

如果上述方法没有用,那么您可以执行以下操作:

  1. 打开选择列表,从 UI 中记下索引的数量及其相应的值。
  2. 在代码中创建一个枚举,并将这些值/索引分配给它。
  3. 在运行时使用枚举(在上面的示例中给出)来设置选项列表。

但不知何故,索引可能会在一段时间内发生变化,因此在这种情况下,您可以使用这些值/索引创建一个枚举 xml,并在运行时加载它们。但这种方法的问题是:

  1. 每次有人要更改索引(这种情况很少见)时,管理员还必须更改 xml 文件。
  2. 加载外部 xml 文件是一项开销。

不太好的方法,但是在紧迫的最后期限内,这是你可以做的;这永远不会破坏或造成麻烦。只是 xml 加载部分不太好。

顺便说一句,如果您浏览 CRM SDK,您会发现类似的示例。

If its a pick list, you will have to provide the index value. Assuming that you have an enum called TargetValues.Contact having value 1, then it would go like:

map.targetentity = new Picklist();
//map.targetentity.name = "Contact"
map.targetentity.Value = Convert.ToInt32(TargetEntities.Contact);

-- Edit --

I believe for what you are trying to achieve you will have to somehow retrieve the target entity and only then you will be able to enumerate them.

See this, probably this would help.

If above is of no use, then following is how you can do it:

  1. Opened picklist, from the UI, write down the number of indices and their cooresponding values.
  2. Created an enum in code, and assign those values/indices to it.
  3. Use enum at runtime(given in example above), to set the picklist.

But then somehow indices may change over a period of time, so in that case you can create an enumerated xml with those values/indices, and load them on runtime. But the problem with this approach is that:

  1. Everytime anyone is going to change the index, which is very rare, the administrator shall also have to change the xml file.
  2. Load an external xml file is an overhead.

Not-so-good approach, but running against a ticking deadline this is what you can do; this is never going to break or cause trouble. Just that xml loading part is not good.

Btw, if you would go through the CRM SDK, you will find the examples of similar sort.

缱绻入梦 2024-08-19 03:06:10

使用此函数动态请求选项列表值:

public IDictionary<int,string> PickListValues(string entityname, string attributename)
{
    var req = new RetrieveAttributeRequest();
    req.EntityLogicalName = entityname;
    req.LogicalName = attributename;
    req.RetrieveAsIfPublished = true;

    var response = (RetrieveAttributeResponse)Service.MetaDataService.Execute(req);

    var picklist = (PicklistAttributeMetadata)response.AttributeMetadata;

    var res = new Dictionary<int,string>();

    foreach (var item in picklist.Options)
       res.Add(item.Value.Value, item.Label.UserLocLabel.Label);

    return res;
}

Take this function to dynamic request picklist values:

public IDictionary<int,string> PickListValues(string entityname, string attributename)
{
    var req = new RetrieveAttributeRequest();
    req.EntityLogicalName = entityname;
    req.LogicalName = attributename;
    req.RetrieveAsIfPublished = true;

    var response = (RetrieveAttributeResponse)Service.MetaDataService.Execute(req);

    var picklist = (PicklistAttributeMetadata)response.AttributeMetadata;

    var res = new Dictionary<int,string>();

    foreach (var item in picklist.Options)
       res.Add(item.Value.Value, item.Label.UserLocLabel.Label);

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