Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# dynamics crm插件错误_C#_Plugins_Dynamics Crm_Crm - Fatal编程技术网

C# dynamics crm插件错误

C# dynamics crm插件错误,c#,plugins,dynamics-crm,crm,C#,Plugins,Dynamics Crm,Crm,我的插件有问题,我有一个自定义实体new_smsmessage,我想从我的插件中检索自定义属性以发送文本消息,但它给我以下错误消息“字典中不存在给定的密钥”。插件代码如下所示,CRM实体中的属性名称正确无误: public void Execute(IServiceProvider serviceProvider) { ITracingService tracingService = (ITracingService)serviceProvider.GetService(

我的插件有问题,我有一个自定义实体
new_smsmessage
,我想从我的插件中检索自定义属性以发送文本消息,但它给我以下错误消息“字典中不存在给定的密钥”。插件代码如下所示,CRM实体中的属性名称正确无误:

public void Execute(IServiceProvider serviceProvider)
{
    ITracingService tracingService =
        (ITracingService)serviceProvider.GetService(typeof(ITracingService));

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

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

   string uservalue = "";
   string phonevalue = "";
   string aliasevalue = "";

   ColumnSet columnSet = new ColumnSet(true);
   ColumnSet allFields = new ColumnSet() { AllColumns = true };
   ExternalSMSService1.ExternalSMSService wbSrvSMS = new ExternalSMSService1.ExternalSMSService();
   string strToken = wbSrvSMS.Login(userName, pwd);
   string smsResult = string.Empty;

   if (entity.Attributes.Contains("new_username"))
   {
       uservalue = entity.Attributes["new_username"].ToString();
   }
   else
   {
       throw new InvalidPluginExecutionException("field name not found");
   }

   if (entity.Attributes.Contains("new_userphone"))
   {
       phonevalue = entity.Attributes["new_userphone"].ToString();
   }
   else
   {
       throw new InvalidPluginExecutionException("field Phone not found");
   }

   if (entity.Attributes.Contains("new_aliasecode"))
   {
       phonevalue = entity.Attributes["new_aliasecode"].ToString();
   }
   else
   {
       throw new InvalidPluginExecutionException("aliase Phone not found");
   }

   string smsmessage = entity.Attributes["new_message"].ToString();
   string[] strArr = null;
   string[] strArr2;
   char[] splitchar = { ';' };
   strArr = uservalue.Split(splitchar);
   char[] splitchar2 = { '-' };
   strArr2 = phonevalue.Split(splitchar2);

   for (int i = 0; i < strArr.Length; i++)
   {

       StringBuilder strMsg = new StringBuilder();
       strMsg.Append("<SEND_SMS>");
       strMsg.Append("<MSG_DATA TEXT='" + smsmessage + "' SHORT_CODE='" + aliasevalue + "'/>");
       strMsg.Append("<RECIPIENTS>");
       strMsg.Append("<RECIPIENT MOBILE_NUMBER='" + strArr2[i].ToString() + "' RECP_NAME ='" + strArr[i].ToString() + "'/>");
       strMsg.Append("</RECIPIENTS>");
       strMsg.Append("</SEND_SMS>");

       smsResult = wbSrvSMS.SendSMS(strMsg.ToString(), strToken);
   }
}
public void Execute(IServiceProvider服务提供者)
{
ITracingService跟踪服务=
(ITracingService)serviceProvider.GetService(类型(ITracingService));
//从服务提供程序获取执行上下文。
IPluginExecutionContext上下文=(IPluginExecutionContext)serviceProvider.GetService(类型为(IPluginExecutionContext));
实体=(实体)上下文。输入参数[“目标”];
字符串uservalue=“”;
字符串phonevalue=“”;
字符串aliasevalue=“”;
ColumnSet ColumnSet=新列集(true);
ColumnSet allFields=new ColumnSet(){AllColumns=true};
ExternalSMSService1.ExternalSMSService wbSrvSMS=新的ExternalSMSService1.ExternalSMSService();
字符串strToken=wbSrvSMS.Login(用户名,pwd);
string smsResult=string.Empty;
if(entity.Attributes.Contains(“新用户名”))
{
uservalue=entity.Attributes[“new_username”].ToString();
}
其他的
{
抛出新的InvalidPluginExecutionException(“未找到字段名”);
}
if(entity.Attributes.Contains(“new_userphone”))
{
phonevalue=entity.Attributes[“new_userphone”].ToString();
}
其他的
{
抛出新的InvalidPlugineExecutionException(“未找到现场电话”);
}
if(entity.Attributes.Contains(“新别名代码”))
{
phonevalue=entity.Attributes[“new_aliasecode”].ToString();
}
其他的
{
抛出新的InvalidPlugineExecutionException(“未找到别名电话”);
}
字符串smsmessage=entity.Attributes[“new_message”].ToString();
字符串[]strArr=null;
字符串[]strArr2;
char[]splitchar={';'};
strArr=uservalue.Split(splitchar);
char[]splitchar2={'-'};
strArr2=phonevalue.Split(splitchar2);
对于(int i=0;i
尝试更改行

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


现在没事了,我只是忘了修改变量
谢谢

在喜欢之前一定要先检查钥匙

if (_entity.Attributes.ContainsKey("field1"))
{Here code to get field1 value }

因为返回实体不包含具有空值的属性。

我这样做了,现在我收到一条新的错误消息“索引超出了数组的边界”
if (_entity.Attributes.ContainsKey("field1"))
{Here code to get field1 value }