Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.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
Plugins dynamics crm插件查找字段_Plugins_Dynamics Crm 2011_Lookup - Fatal编程技术网

Plugins dynamics crm插件查找字段

Plugins dynamics crm插件查找字段,plugins,dynamics-crm-2011,lookup,Plugins,Dynamics Crm 2011,Lookup,我已经尝试了很多代码,但仍然不起作用,我是dynamics crm 2011的开发者。我已经创建了新的自定义实体“new_smsmessage”,它与用户实体有多对多的关系,我正在编写插件向许多用户发送短信,我需要在我的插件中检索用户mobilenumber,我使用下面的代码检索用户ID,但总是在crm中收到错误消息“给定的密钥在讨论中不存在” 任何帮助plz: if (context.InputParameters.Contains("Target") &&

我已经尝试了很多代码,但仍然不起作用,我是dynamics crm 2011的开发者。我已经创建了新的自定义实体“new_smsmessage”,它与用户实体有多对多的关系,我正在编写插件向许多用户发送短信,我需要在我的插件中检索用户mobilenumber,我使用下面的代码检索用户ID,但总是在crm中收到错误消息“给定的密钥在讨论中不存在” 任何帮助plz:

if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)
            {
                 Entity entity = (Entity)context.InputParameters["Target"];


                if (entity.Attributes.Contains("new_smsmessage") == false)
                {

                    string smstext = entity.Attributes["new_message"].ToString();
                    string smsnumber = entity.Attributes["new_phonenumber"].ToString();

                    EntityReference userlookup = (EntityReference)entity["systemuser"];

                    string receipient = userlookup.Name.ToString();
                }
 }

很可能
systemuser
不是属性的名称。如果它是
新消息
记录的所有者,则它将是
(EntityReference)实体[“ownerid”]
。如果它是一个自定义属性,是用户的查找,那么它将类似于以下
(EntityReference)实体[“new\u systemuser”]


在插件代码中使用属性之前,还应该检查属性是否存在

以下是完整的代码

public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
                serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)
            {

                Entity entity = new Entity("New_smsmessage");

                ExternalSMSService1.ExternalSMSService wbSrvSMS = new ExternalSMSService1.ExternalSMSService();

                string strToken = wbSrvSMS.Login(userName, pwd);
                string smsResult = string.Empty;
                string smstext = entity.Attributes["new_message"].ToString();
                string smsnumber = entity.Attributes["new_phonenumber"].ToString();
                EntityReference aliaselookup = (EntityReference)entity.Attributes["new_aliaseid"].ToString;

                switch (strToken)
                {
                    case "01":
                        Console.WriteLine("Invalid Username or pwd");
                        break;

                    case "03":
                        Console.WriteLine("Host Application Down");
                        break;

                    default:
                        StringBuilder strMsg = new StringBuilder();
                        strMsg.Append("<SEND_SMS>");
                        strMsg.Append("<MSG_DATA TEXT='" + smstext + "' SHORT_CODE='" + aliaselookup + "'/>");
                        strMsg.Append("<RECIPIENTS>");
                        strMsg.Append("<RECIPIENT MOBILE_NUMBER='" + smsnumber + "' RECP_NAME ='tester'/>");
                        strMsg.Append("</RECIPIENTS>");
                        strMsg.Append("</SEND_SMS>");

                        smsResult = wbSrvSMS.SendSMS(strMsg.ToString(), strToken);

                        switch (smsResult)
                        {
                            case "01":
                                Console.WriteLine("Invalid or Expired token");
                                break;

                            case "02":
                                Console.WriteLine("Incorrect input XML format");
                                break;

                            case "03":
                                Console.WriteLine("Host Application down");
                                break;

                            default:
                                Console.WriteLine("SMS Sent Successfully");
                                break;
                        }

                        break;
                    // }

                }
            }
        }
public void Execute(IServiceProvider服务提供者)
{
//从服务提供程序获取执行上下文。
Microsoft.Xrm.Sdk.IPluginExecutionContext上下文=(Microsoft.Xrm.Sdk.IPluginExecutionContext)
GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
//InputParameters集合包含消息请求中传递的所有数据。
if(context.InputParameters.Contains(“目标”)&&
context.InputParameters[“Target”]是实体)
{
实体=新实体(“新信息”);
ExternalSMSService1.ExternalSMSService wbSrvSMS=新的ExternalSMSService1.ExternalSMSService();
字符串strToken=wbSrvSMS.Login(用户名,pwd);
string smsResult=string.Empty;
字符串smstext=entity.Attributes[“new_message”].ToString();
字符串smsnumber=entity.Attributes[“new_phonenumber”].ToString();
EntityReference别名查找=(EntityReference)entity.Attributes[“new_aliaseid”]。ToString;
开关(斯特肯)
{
案例“01”:
Console.WriteLine(“无效用户名或密码”);
打破
案例“03”:
Console.WriteLine(“主机应用程序关闭”);
打破
违约:
StringBuilder strMsg=新的StringBuilder();
strMsg.追加(“”);
strMsg.追加(“”);
strMsg.追加(“”);
strMsg.追加(“”);
strMsg.追加(“”);
strMsg.追加(“”);
smsResult=wbSrvSMS.SendSMS(strMsg.ToString(),strToken);
开关(smsResult)
{
案例“01”:
Console.WriteLine(“无效或过期令牌”);
打破
案例“02”:
WriteLine(“不正确的输入XML格式”);
打破
案例“03”:
Console.WriteLine(“主机应用程序关闭”);
打破
违约:
Console.WriteLine(“短信发送成功”);
打破
}
打破
// }
}
}
}

但是,我将自定义属性更改为查找字段的名称,它给出了相同的错误:我认为问题在于这一行:
实体实体=新实体(“新消息”)相反,它应该是
实体=(实体)上下文。InputParameters[“Target”]
。因为您正在将实体设置为新的
实体
类,所以没有与之关联的属性,这就是为什么您得到的
是因为给定的键不存在于disctionary
错误中。