簡體   English   中英

如何使用 Xrm Web Api 更新 Microsoft 模型驅動應用程序中的自定義查找字段?

[英]How to update a custom lookup field in a Microsoft Model-driven App using the Xrm Web Api?

我有一個我公司正在使用的 dynamics 365 crm,我們有一堆我們添加的自定義表格,彼此有很多查找字段。 當某些事件發生時,我正在嘗試使用 javascript 更新其中一些查找字段。 我已經遵循了文檔(雖然很少)我基於此的代碼是:

Xrm.WebApi.updateRecord("new_nursesdatabase", "aa09e593-a624-ed11-b83e-000d3a371e11", {"new_personnelstatus_custom@odata.bind": "/new_personnelstatus_custom(5052e892-5aee-ec11-bb3d-000d3a5a2232)"}). 然后(函數成功(結果){console.log(結果)})

其中第一個 new_personnelstatus_custom 指的是 new_nursesdatabase 中的字段,第二個指的是第一個字段指向的表(我不是為這些實體創建邏輯名稱的人)。

運行這個我得到錯誤:

[storage] Error Messages: 
1: Error identified in Payload provided by the user for Entity :'', For more information on this error please follow this help link [Removed to avoid spam filter] InnerException : Microsoft.OData.ODataException: The navigation property 'new_PersonnelStatus_Custom' has no expanded value and no 'odata.bind' property annotation. Navigation property in request without expanded value must have the 'odata.bind' property annotation.

我點擊了錯誤代碼中提供的鏈接,那里的文檔告訴我要確保導航屬性存在,通過搜索 CSDL 元數據文檔我確實找到了 new_personnelstatus_custom 字段,盡管它使用的是模式名稱 new_PersonnelStatus_Custom 而不是邏輯名稱我在上面使用過,改變它並運行:

Xrm.WebApi.updateRecord("new_nursesdatabase", "aa09e593-a624-ed11-b83e-000d3a371e11", {"new_PersonnelStatus_Custom@odata.bind": "/new_personnelstatus_custom(5052e892-5aee-ec11-bb3d-000d3a5a2232)"}).then (函數成功(結果){console.log(結果)})

給我這個錯誤信息:

[storage] Error Messages: 
1: URL was not parsed due to an ODataUnrecognizedPathException. Resource not found for the segment provided in the URL.

(大寫表名沒有區別)。 我不確定這是向前進展還是向后進展,就好像我用大寫字母拼錯了字段名稱,這讓我遇到了第一個錯誤,所以它清楚地識別了這個實體,而不是它似乎對待相同的非大寫版本作為一個彌補的領域。 這是一個單值查找字段,即它一次只能有一個值,並且只能引用一個表所以它不是多表查找問題,提供的GUID是直接從記錄中獲取的所以應該是准確的(而且我希望我會得到不同類型的錯誤,如果其他一切正常並且他們錯了)。 我已經搜索了 inte.net,但沒有發現任何跡象表明代碼不應該像寫的那樣工作。

使用 Guido Preite 提供的 Dataverse REST 構建器后,我能夠找到導致問題的缺失字母。 顯然您需要為列使用架構名稱,而且您似乎需要為表使用“復數邏輯”名稱。 我沒有找到對邏輯名稱的任何引用,我不得不深入研究 REST 構建器的底層代碼以找出它在哪里找到它,但顯然我需要為表使用 new_personnelstatus_customs 而不是 new_personnelstatus_custom,盡管 new_personnelstatus_customs 既不是邏輯名稱 (new_personnelstatus_custom) 和架構名稱 (new_PersonnelStatusCustom),我只能假設 Dataverse 在某些上下文中將表的邏輯名稱復數化,如果為真,這很奇怪。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM