[英]dynamics crm plugin error
我的插件有问题,我有一个自定义实体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);
}
}
尝试换线
Entity entity = (Entity)context.InputParameters["target"];
至
Entity entity = (Entity)context.InputParameters["Target"];
没关系,我只是忘记修改变量了
总是先检查一下钥匙再得到喜欢。
if (_entity.Attributes.ContainsKey("field1"))
{Here code to get field1 value }
因为返回实体不包含具有空值的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.