2016-07-26 65 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

相關問題