我正在使用以下代码尝试从 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]
谁能解释这里发生了什么?
谢谢,
杰克