我正在使用OData与Sharepoint托管的应用程序一起工作。我正在尝试使用其BdcIdentity创建项目后将附件文件添加到列表项目,但我收到以下错误:
{"readyState":4,"responseText":"{"error":{"code":"-2146232832,Microsoft.SharePoint.SPException","message":{"lang\":"en-US","value":"The List item must be saved to the content database before adding an attachment. To resolve this problem, save the list item and then add the attachment."}}}","status":500,"statusText":"Internal Server Error"}
创建列表项的代码:
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('tbl_FeedbackDetails')/Items/",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose"
},
data: JSON.stringify(details),
success.....
下面是我创建项目后的代码(我在第一个ajax调用的成功函数中运行此代码):
var queryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/lists/GetByTitle('ListName')/GetItemByStringId('BdcIdentity')/AttachmentFiles/add(FileName='filename')";
$.ajax({
url: queryUrl,
type: "POST",
processData: false,
contentType: "application/json;odata=verbose",
data: buffer,
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
console.log(JSON.stringify(data));
console.log('Attachement Added Successfully');
},
error: function (error) {
console.log("Failure:" + error.status + "," + error.statusText);
console.log('Error full-text: ' + JSON.stringify(error));
}
});
第一次调用成功创建了列表项。我做得对吗?