[英]Sharepoint 2013 Rest API: create to multivalue column
I'm trying to save some values to a multi value field, more precisely a survey list column. 我正在尝试将一些值保存到多值字段,更确切地说是调查列表列。 My attempts:
我的尝试:
$.ajax({
url: "somesitecollection/_api/web/lists/getByTitle('survey')/items",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify({
'__metadata': {
'type': 'SP.Data.SurveyListItem'
},
'Question1': {
"__metadata": {
"type": "Collection(SP.FieldRatingScaleQuestionAnswer)"
},
"results": [2, 3, 5]
},
'Comment': "Thanks for..."
}),
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
console.log("done");
},
error: function (err) {
console.log(err.status + " - " + err.responseJSON.error.message.value);
}
});
I think there's something wrong with the "results" part in the "Question1" JSON, don't really find the problem though. 我认为“ Question1” JSON中的“结果”部分出了问题,但实际上并没有发现问题。
Error message: 错误信息:
"400: An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected."
“ 400:从JSON读取器读取时,发现意外的'PrimitiveValue'节点。应为'StartObject'节点。”
What does that mean? 这意味着什么?
Tried with this code: 尝试使用此代码:
$.ajax({
url: "somesitecollection/_api/web/lists/getByTitle('survey')/items",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify({
'__metadata': {
'type': 'SP.Data.SurveyListItem'
},
'Question1': {
"__metadata": {
"type": "Collection(SP.FieldRatingScaleQuestionAnswer)"
},
"results": [
{
"Answer": 1
}, {
"Answer": 5
}, {
"Answer": 4
}
]
},
'Comment': "Thanks for..."
}),
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
},
success: function (data) {
console.log("ok");
},
error: function (err) {
console.log(err.status + " - " + err.responseJSON.error.message.value);
}
});
No errors now. 现在没有错误。 Only the comment is saved though.
但是,仅保存注释。 Any idea?
任何想法?
A while after posting I found the solution. 发布一段时间后,我找到了解决方案。 You have to give the question too:
您也必须提出一个问题:
"results": [
{
"Answer": 1,
"Question": "Question 1"
}, {
"Answer": 5,
"Question": "Question 2"
}, {
"Answer": 4,
"Question": "Question 3"
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.