尝试通过Web API创建记录时出现“未声明的属性" [英] 'An undeclared property' when trying to create record via Web API

查看:96
本文介绍了尝试通过Web API创建记录时出现“未声明的属性"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个我似乎无法调试的错误.我正在尝试通过自定义HTML/JavaScript Web资源创建自定义活动实体.

I am getting an error which I just cannot seem to debug. I am trying to create a custom activity entity via custom HTML/JavaScript web resource.

用户单击按钮和以下参数:

The user clicks a button and the following params:

var params = {
    'rob_faqid@odata.bind': '/rob_faqs(guid-here)',
    'rob_source': 180840000,
    'subject': 'Signpost',
    'actualstart': new Date(),
    'actualend': new Date()
};

已传递到此URL:

https://dynamicsorg/api/data/v8.2/rob_quickactions/

具有以下标题:

xhr.setRequestHeader('OData-MaxVersion', '4.0');
xhr.setRequestHeader('OData-Version', '4.0');
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.setRequestHeader('Prefer', 'return=representation');

这为我提供了400 (bad request)的HTTP代码和以下错误消息:

This gives me a HTTP code of 400 (bad request) and this error message:

An undeclared property 'rob_faqid' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.

有趣的是,无论是使用实际的GUID还是在其中放置乱码(都与传入的值无关),我都会收到此错误.

Interestingly, I get this error whether I use an actual GUID or if I put some gibberish in there (suggesting it is not to do with the value being passed in).

我可以通过标准表格手动创建记录.

I can create the records manually via the standard form.

我在同一项目中的其他位置使用odata.bind,没有错误.

I am using the odata.bind elsewhere within the same project with no errors.

推荐答案

一夜安眠后,我意识到自己的错误.要设置查找字段的值,您需要使用关系方案名称,而不是属性名称.

After a good night's sleep I realised my error. To set the value of a lookup field, you need to use the relationship scheme name, and not the property name.

一旦我改变了一切,一切都很好.

Once I changed that, all worked fine.

这篇关于尝试通过Web API创建记录时出现“未声明的属性"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆