gpt4 book ai didi

dynamics-crm-2011 - 如何在 Dynamics CRM Online 中更新已部署的插件

转载 作者:行者123 更新时间:2023-12-04 05:09:13 25 4
gpt4 key购买 nike

我刚开始在 Dynamics CRM Online 中编程,并且在更新已部署的插件时遇到问题。我使用 Visual Studio 2012 作为我的 IDE。我部署了一个需要修改的插件,当我通过 VS 重新部署它时,CRM 中的修改日期是正确的,但更改不存在。这是我的代码..

if (context.InputParameters.Contains("Target") 
&& context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "lead")
{
if (entity.Attributes.Contains("companyname") == true)
{
if (entity["firstname"].ToString() != "null")
firstName = entity["firstname"].ToString();
else
firstName = "";

if (entity["lastname"].ToString() != "null")
lastName = entity["lastName"].ToString();
else
lastName = "";

entity["companyName"] = "This is a test";
//entity["companyname"] = firstName + " " + lastName;
}
else
throw new InvalidPluginExecutionException(
"The company name can only be set by the system.");
}
}

当我创建潜在客户时,公司名称不是“这是一个测试”。我不确定我做错了什么。

感谢您的帮助!

最佳答案

您通过以下方式检测具有公司名称的字段是否存在:

if (entity.Attributes.Contains("companyname") == true)

但是你写信给另一个人,即:

entity["companyName"] = "This is a test";

该值放在实体中,但由于它在元数据中没有对应项,因此不会被存储。将字段名称设置为模式名称,即小写。

如果您遇到其他错误,还需要考虑其他一些事项。
  • 设置字段值后,您需要在服务上调用 Update 方法。
  • 该字段应该有某种前缀(例如 new_something、beep_something)。
  • 驼峰式大小写在这里不适用(模式名称是),所以全部转为小写。

  • 什么 你得到的公司名称?您是否收到抛出的异常?

    此外,还有一些关于代码质量的指针。我重建了逻辑以消除不必要的范围复杂性。我删除了多余的 else 语句和与 true 的比较。我还建议您将过程拆分为不同的方法,但我相信您已经了解了这一点。您可能希望使用辅助方法从字段中获取值。见 in this post at my suggestion .

    if (!context.InputParameters.Contains("Target") ||
    context.InputParameters["Target"] is Entity)
    return;

    Entity entity = context.InputParameters["Target"] as Entity;
    if (entity.LogicalName != "lead")
    return;
    if (!entity.Attributes.Contains("companyname"))
    throw new InvalidPluginExecutionException(
    "The company name can only be set by the system.");

    String firstName = String.Empty;
    if (entity.Contains("firstname"))
    firstName = entity["firstname"] as String;

    String lastName = String.Empty;
    if (entity.Contains("lastname"))
    lastName = entity["lastname"] as String;

    entity["companyname"] = "This is a test";
    //entity["companyname"] = firstName + " " + lastName;

    编辑:

    如果您仍然没有得到请求的行为,请尝试以下操作。 (我不确定你的专业知识水平如何,所以如果你因为我提到一些你已经尝试过无数次的非常基本的东西而感到侮辱,请接受我的道歉。)

    技术诀窍。
  • 发布所有自定义设置(我经常这样做 非常 ,以防万一)。
  • 按 F5 重新加载。
  • 登录/注销。
  • 重新启动 IIS(如果是内部部署)。
  • 取消注册插件,看看行为是否仍然存在。 然后重新注册它。
  • 检查被遗忘的工作流正在运行。

  • 可能会有一些延迟和滞后。有一次,我实际上同时触发了旧版本和新版本的插件,这取决于我是从“设置”还是“工作区”创建记录。这很奇怪,但几个小时后自行解决。认真的。 那个很奇怪!

    程序化技巧。
  • 检查是否还有其他您可能忘记停用的插件。
  • 删除所有线索并确保插件在创建新线索时触发。
  • 将文本更改为例如我是一只巨大的驼鹿,只是为了确保改变能够通过。
  • 删除所有代码(或将 return 放在 Execute 的开头。然后,逐步将其向下移动以检测异常何时开始。

  • 在你所展示的内容中,它应该可以工作,所以要么你没有提到相关的东西(我们 当然感谢你没有发布 100000 行代码),或者是 CRM 很奇怪(这同样令人讨厌和困惑)。所以,让我们解决这个问题。当您尝试上述技巧时会发生什么?

    至于代码 stub ,是的 - 我对 MS 在那里的努力并不太感到自豪。尝试将该代码发布在 Programmers 上的标记 C# 下以进行代码审查。准备好进行愤怒的讨论。 :)

    关于dynamics-crm-2011 - 如何在 Dynamics CRM Online 中更新已部署的插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15099650/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com