繁体   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