简体   繁体   English

如何使用 Xrm Web Api 更新 Microsoft 模型驱动应用程序中的自定义查找字段?

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

I have a dynamics 365 crm that my company is using and we have a bunch of custom tables that we've added, with a lot of lookup fields to each other.我有一个我公司正在使用的 dynamics 365 crm,我们有一堆我们添加的自定义表格,彼此有很多查找字段。 I'm trying to use javascript to update some of these lookup fields when certain events occur.当某些事件发生时,我正在尝试使用 javascript 更新其中一些查找字段。 I've followed the documentation (minimal as it is) My code based on this is:我已经遵循了文档(虽然很少)我基于此的代码是:

Xrm.WebApi.updateRecord("new_nursesdatabase", "aa09e593-a624-ed11-b83e-000d3a371e11", {"new_personnelstatus_custom@odata.bind": "/new_personnelstatus_custom(5052e892-5aee-ec11-bb3d-000d3a5a2232)"}).then(function success(result) {console.log(result)}) 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(结果)})

where the first new_personnelstatus_custom refers to the field in the new_nursesdatabase and the second one refers to the table that the first field points to (I was not the one who created the logical names for these entities).其中第一个 new_personnelstatus_custom 指的是 new_nursesdatabase 中的字段,第二个指的是第一个字段指向的表(我不是为这些实体创建逻辑名称的人)。

Running this I get the error:运行这个我得到错误:

[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.

I followed the link provided in the error code, and was told by the documentation there to ensure that the navigation property exists, which searching through the CSDL metadata document I did find the new_personnelstatus_custom field though it used the schema name new_PersonnelStatus_Custom rather than the logical name I used above, changing that and running:我点击了错误代码中提供的链接,那里的文档告诉我要确保导航属性存在,通过搜索 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(function success(result) {console.log(result)}) 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(结果)})

gets me this error message:给我这个错误信息:

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

(Capitalizing the table name made no difference). (大写表名没有区别)。 I'm not certain if this is forward progress or backwards progress as if I misspell the field name with the capitalizations it gets me the first error so it's clearly recognizing this entity as opposed to the non-capitalized version which it seems to treat the same as a made up field.我不确定这是向前进展还是向后进展,就好像我用大写字母拼错了字段名称,这让我遇到了第一个错误,所以它清楚地识别了这个实体,而不是它似乎对待相同的非大写版本作为一个弥补的领域。 This is a single-valued lookup field, that is it can only have one value at a time and can only refer to one table so it's not a multi-table lookup issue, the GUIDs provided were taken directly from the record so should be accurate (and I expect that I would get a different type of error were everything else working and they were wrong).这是一个单值查找字段,即它一次只能有一个值,并且只能引用一个表所以它不是多表查找问题,提供的GUID是直接从记录中获取的所以应该是准确的(而且我希望我会得到不同类型的错误,如果其他一切正常并且他们错了)。 I've scoured the inte.net but have not found any indications that the code shouldn't work as written.我已经搜索了 inte.net,但没有发现任何迹象表明代码不应该像写的那样工作。

After using the Dataverse REST builder provided by Guido Preite, I was able to find the missing letter that was causing problems.使用 Guido Preite 提供的 Dataverse REST 构建器后,我能够找到导致问题的缺失字母。 Apparently you need to use the schema name for the column, and it seems like you need to use the "plural logical" name for the table.显然您需要为列使用架构名称,而且您似乎需要为表使用“复数逻辑”名称。 I didn't find any reference to the logical name and I'd have to dig into the code underlying the REST builder to figure out where it found this, but apparently I needed to use new_personnelstatus_customs instead of new_personnelstatus_custom for the table despite new_personnelstatus_customs being neither the logical name (new_personnelstatus_custom) nor the schema name (new_PersonnelStatusCustom) and I can only assume that either Dataverse pluralized the logical name of the table in certain contexts which is bizarre if true.我没有找到对逻辑名称的任何引用,我不得不深入研究 REST 构建器的底层代码以找出它在哪里找到它,但显然我需要为表使用 new_personnelstatus_customs 而不是 new_personnelstatus_custom,尽管 new_personnelstatus_customs 既不是逻辑名称 (new_personnelstatus_custom) 和架构名称 (new_PersonnelStatusCustom),我只能假设 Dataverse 在某些上下文中将表的逻辑名称复数化,如果为真,这很奇怪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 2模型驱动表单中的默认无效选择选项? - Default invalid select option in Angular 2 model-driven forms? Angular2模型驱动的表单验证器模式 - Angular2 model-driven form validator pattern Microsoft Dynamics CRM 中来自 Web API 的查找字段格式化值未定义(无法获取格式化值) - Lookup field formatted value from Web API in Microsoft Dynamics CRM is undefined (cannot get formatted value) 在 Dynamics 365 XRM Web API 中创建记录时无法设置多选选项字段 - Cannot set multi-select option field when creating record in Dynamics 365 XRM Web API WordPress:使用API​​ Javascript更新自定义字段 - Wordpress: Update Custom Field using API Javascript Dynamics Xrm Web API upsert操作 - Dynamics Xrm Web API upsert operation 使用 Ajax 时如何在自定义列表上显示查找字段 - How to display a lookup field on a custom list when using Ajax 如何使用模型驱动的表单来验证Angle 2中的电子邮件字段 - How do you validate an email field in angular 2 using model driven form 在Rails应用程序中使用AJAX无需使用表单即可更新模型字段 - Using AJAX in a rails app to update a model field without using a form 使用Xrm.Navigation.openWebResource()后如何从Web资源取回表单数据 - How to get back form data from Web resource after using Xrm.Navigation.openWebResource()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM