Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.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# 从Silverlight应用程序更新查找字段-CRM 2011_C#_Javascript_Silverlight_Dynamics Crm 2011 - Fatal编程技术网

C# 从Silverlight应用程序更新查找字段-CRM 2011

C# 从Silverlight应用程序更新查找字段-CRM 2011,c#,javascript,silverlight,dynamics-crm-2011,C#,Javascript,Silverlight,Dynamics Crm 2011,我正在使用以下代码尝试从silverlight应用程序更新CRM 2011系统中的查找字段值: try { ma.my_ActionDetails = details; Guid userId = new Guid(); foreach (SystemUser s in SystemUsers) { if (s.FullName.Equals(comboBox1.SelectedItem)) { userI

我正在使用以下代码尝试从silverlight应用程序更新CRM 2011系统中的查找字段值:

try
{
    ma.my_ActionDetails = details;

    Guid userId = new Guid();
    foreach (SystemUser s in SystemUsers)
    {
        if (s.FullName.Equals(comboBox1.SelectedItem))
        {
            userId = s.SystemUserId;
        }
    }

    // Define eval statements for setting lookup to a value and null
    string setLookupJscript = @"Xrm.Page.getAttribute(""{0}"").setValue([ {{ id: ""{1:B}"", typename: ""{2}"", name: ""{3}"" }}])";
    string evalStatement = null;

    // Set the statement to be evaluated based upon the value of the id argument
    // Setting the lookup to a value 
    evalStatement = string.Format(setLookupJscript, "my_salesperson", userId, "my_memberaction", ma.my_SalesPerson.Name);

    HtmlPage.Window.Eval(evalStatement);

    _context.UpdateObject(ma);
    _context.BeginSaveChanges(OnUpdateAccountComplete, ma);
}
catch (SystemException se)
{
    _syncContext.Send(new SendOrPostCallback(showErrorDetails), se);
}
但是,当我运行此代码时,它会生成以下错误:

在浏览器中:

'Xrm' is undefined
从代码中:

System.InvalidOperationException: [Common_MethodFailed]
有人能解释一下这是怎么回事吗

谢谢


Jack

您需要在CRM表单的上下文中才能使用Xrm名称空间。你是从一个表格里跑出来的吗

从:

如果Silverlight web资源设计为在实体窗体中查看,则该窗体具有一个Xrm.Page.context对象,可用于访问上下文信息

如果需要Silverlight应用程序出现在表单上下文之外,则必须配置HTML web资源,通过添加对ClientGlobalContext.js.aspx页面的引用来提供此上下文信息。添加此引用后,Silverlight应用程序可以以与实体表单中相同的方式访问上下文信息。以下示例显示如何从Xrm.Page.context对象调用getServerUrl函数

private string serverUrl = "";
ScriptObject xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
ScriptObject page = (ScriptObject)xrm.GetProperty("Page");
ScriptObject pageContext = (ScriptObject)page.GetProperty("context");
serverUrl = (string)pageContext.Invoke("getServerUrl");