使用Xrm Web Api更新Dynamics 365自定义查找字段遇错求助
解决Dynamics 365 Web API更新单值查找字段的资源找不到错误
核心问题定位
你遇到的ODataUnrecognizedPathException错误,本质是odata.bind路径中使用了目标实体的单数逻辑名称,而非Web API要求的复数实体集名称。Dynamics 365 Web API的实体访问路径必须使用实体的复数形式(由系统自动生成或自定义设置),单数名称会被识别为无效路径。
解决方案步骤
获取目标实体的复数逻辑名称
访问你的CRM环境的元数据端点:[CRM环境URL]/api/data/v9.2/$metadata,搜索目标实体的单数逻辑名称(new_personnelstatus_custom),找到对应的<EntitySet>节点,比如:<EntitySet Name="new_personnelstatus_customs" EntityType="Microsoft.Dynamics.CRM.new_personnelstatus_custom" />这里的
Name属性值(new_personnelstatus_customs)就是需要用到的复数名称。修正Web API代码
将odata.bind路径中的单数实体名称替换为复数名称,同时保留之前确认正确的导航属性名称(new_PersonnelStatus_Custom):Xrm.WebApi.updateRecord("new_nursesdatabase", "aa09e593-a624-ed11-b83e-000d3a371e11", { "new_PersonnelStatus_Custom@odata.bind": "/new_personnelstatus_customs(5052e892-5aee-ec11-bb3d-000d3a5a2232)" }).then(function success(result) { console.log(result); }, function(error) { console.error(error.message); // 增加错误捕获便于排查 });额外排查点
- 验证目标实体路径正确性:直接在浏览器中访问
[CRM环境URL]/api/data/v9.2/new_personnelstatus_customs(5052e892-5aee-ec11-bb3d-000d3a5a2232),如果能返回目标记录的JSON数据,说明路径完全正确。 - 检查权限:确保当前操作的用户拥有
new_nursesdatabase记录的更新权限,以及目标new_personnelstatus_custom记录的读取权限,权限不足也可能触发资源找不到的报错。
- 验证目标实体路径正确性:直接在浏览器中访问
内容的提问来源于stack exchange,提问作者Trevyn Case
相关产品推荐
相关产品推荐

