2016-07-26 66 views
0

我正在尝试开发一个应用程序以允许通过gridview更新我们的CRM数据库。从C更新CRM查找字段#

我所拥有的一切都在努力,直到试图更新查找字段。试图查找字段添加到更新它给了我一个错误,当

_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); 

现在:

以下是工作的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); 
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 

回答

1

只是为了确保,一个名为tog_techidname或者只是tog_techid查找字段?每个查找都有一个关联的名称字段,即查找名称+“名称”,但不能直接更新。只需使用EntityReference更新id就足够了。

尝试用

aspiration["tog_techid"] = new EntityReference("equipment", new Guid(ddlVet.SelectedValue)); 
+0

我只是去尝试,它与同样的错误失败。我不是100%确定“设备”是正确的。 EntityReference()的参数应该是什么? – MMoore94

+0

也是“tog_techidname”是数据库中的列名称。我查看了数据库中的设备视图,它包含设备名称和名称。它不包含equipmentidname。 – MMoore94

+0

CRM实体中字段的名称是什么? EntityReference应该是一对实体的LogicalName和一个Guid,没有别的。 – Jordi

相关问题