c# - MS CRM 插件的一般错误

标签 c# dynamics-crm-2011 runtime-error dynamics-crm

我正在尝试运行 MS CRM 的示例插件。但我收到以下错误:

An error occurred. Contact a system administrator or refer to the Microsoft Dynamics CRM SDK troubleshooting guide.

这是代码:

public void Execute(IServiceProvider serviceProvider)
    {

        // Obtain the execution context from the service provider.
        IPluginExecutionContext context = (IPluginExecutionContext)
        serviceProvider.GetService(typeof(IPluginExecutionContext));


        // The InputParameters collection contains all the data passed in the message request.
        if (context.InputParameters.Contains("account") &&
        context.InputParameters["account"] is Entity)
        {
            // Obtain the target entity from the input parmameters.
            Entity entity = (Entity)context.InputParameters["account"];



            try
            {
                //check if the account number exist

                if (entity.Attributes.Contains("account number") == false)
                {

                    //create a task
                    Entity task = new Entity("task");
                    task["subject"] = "Account number is missing";
                    task["regardingobjectid"] = new EntityReference("account", new Guid(context.OutputParameters["id"].ToString()));

                    //adding attribute using the add function
                    // task["description"] = "Account number is missng for the following account. Please enter the account number";
                    task.Attributes.Add("description", "Account number is missng for the following account. Please enter the account number");



                    // Obtain the organization service reference.
                    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


                    // Create the task in Microsoft Dynamics CRM.
                    service.Create(task);


                }
            }

            catch (FaultException ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
            }

        }

    }
}//end class

这是一个示例代码,我已经验证了该插件使用的所有实体和字段都已定义并且位于该位置。但我不断收到此业务错误。

最佳答案

我找到了解决方案:我们不必明确提及“帐户”,而是必须使用:

Entity entity = (Entity)context.InputParameters["Target"];

第二个错误原因是 CRM 内部的限制,不允许创建新帐户。用于创建新的“联系人”时效果很好。

非常感谢大家的帮助。

关于c# - MS CRM 插件的一般错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17921523/

相关文章:

c# - 如何将@RenderBody() 分成两部分

javascript - window.open 来自 CRM 2011 的 silverlight

sql - Dynamics CRM 2011 安全角色 SQL 查询

linux - 从 crontab 运行 shell 脚本时权限被拒绝

python - 列表索引类型错误

java - Java中的温度转换代码无法运行?

javascript - 如何使用 Jint 从 JavaScript 函数调用中获取正确的 C# 字符串数组

c# - 如何将任何文件夹更改投影到新文件夹并保持原始文件夹不变?

c# - 使用 HTTP 处理文件下载期间丢失的 Internet 连接

workflow - Microsoft Dynamics CRM 2011 使用工作流创建报价产品记录