从 C# 更新 CRM 查找字段
Update CRM Lookup Field from C#
我正在尝试开发一个应用程序以允许通过 gridview 更新我们的 CRM 数据库。
在尝试更新查找字段之前,我所做的一切都在工作。
以下是有效的 C# 代码:
_service = GlobalFunctions.GetServiceAccount();
GlobalFunctions.User u = (GlobalFunctions.User)Session["UserInfo"];
Entity aspiration = new Entity("tog_aspiration");
aspiration.Id = new Guid(inputGridView.DataKeys[e.RowIndex].Value.ToString());
aspiration["tog_nofollrl"] = Int32.Parse(tog_nofollrl);
_service.Update(aspiration);
现在尝试将查找字段添加到更新时出现错误。
_service = GlobalFunctions.GetServiceAccount();
GlobalFunctions.User u = (GlobalFunctions.User)Session["UserInfo"];
Entity aspiration = new Entity("tog_aspiration");
aspiration.Id = new Guid(inputGridView.DataKeys[e.RowIndex].Value.ToString());
aspiration["tog_nofollrl"] = Int32.Parse(tog_nofollrl);
aspiration["tog_techidname"] = new EntityReference("equipment", new Guid(ddlVet.SelectedValue));
_service.Update(aspiration);
这里是错误
Incorrect attribute value type System.String
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Incorrect attribute value type System.String
只是为了确定一下,查找字段的名称是 tog_techidname 还是 tog_techid?每个查找都有一个关联的名称字段,即查找名称 + "name",但您不能直接更新它。只需使用 EntityReference 更新 id 就足够了。
试试
aspiration["tog_techid"] = new EntityReference("equipment", new Guid(ddlVet.SelectedValue));
我正在尝试开发一个应用程序以允许通过 gridview 更新我们的 CRM 数据库。
在尝试更新查找字段之前,我所做的一切都在工作。
以下是有效的 C# 代码:
_service = GlobalFunctions.GetServiceAccount();
GlobalFunctions.User u = (GlobalFunctions.User)Session["UserInfo"];
Entity aspiration = new Entity("tog_aspiration");
aspiration.Id = new Guid(inputGridView.DataKeys[e.RowIndex].Value.ToString());
aspiration["tog_nofollrl"] = Int32.Parse(tog_nofollrl);
_service.Update(aspiration);
现在尝试将查找字段添加到更新时出现错误。
_service = GlobalFunctions.GetServiceAccount();
GlobalFunctions.User u = (GlobalFunctions.User)Session["UserInfo"];
Entity aspiration = new Entity("tog_aspiration");
aspiration.Id = new Guid(inputGridView.DataKeys[e.RowIndex].Value.ToString());
aspiration["tog_nofollrl"] = Int32.Parse(tog_nofollrl);
aspiration["tog_techidname"] = new EntityReference("equipment", new Guid(ddlVet.SelectedValue));
_service.Update(aspiration);
这里是错误
Incorrect attribute value type System.String
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Incorrect attribute value type System.String
只是为了确定一下,查找字段的名称是 tog_techidname 还是 tog_techid?每个查找都有一个关联的名称字段,即查找名称 + "name",但您不能直接更新它。只需使用 EntityReference 更新 id 就足够了。
试试
aspiration["tog_techid"] = new EntityReference("equipment", new Guid(ddlVet.SelectedValue));