0

I'm on a project where I'm implementing a CRUD for a Sharepoint 2013 Document Library which includes two custom content types, the default one I'll call MyDoc which is derived from Document and another type I'll call MyDocSet which is derived from Document Set. I'm doing this with JS/jQuery.

I can't seem to figure out how to set the content type when creating a list item. I want to add an item of content type MyDocSet, but it always wants to assume the default content type.

Here is my unsuccessful attempt:

var executor = new SP.RequestExecutor(baseUrl);
var bodyContent = JSON.stringify({
    "__metadata": {"type": "SP.Data.LineJSubmitItem"},
    //How to set content type ID?
});
executor.executeAsync({
    url: baseUrl + "/sites/linej/_api/web/lists/GetByTitle('LineJSubmit')/items",
    method: "POST",
    headers: {
        "Accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
        "X-RequestDigest": formDigestValue,
        "content-length": bodyContent.length,
    },
    body: bodyContent,
    success: function(data) {
        alert("success");
    },
    error: function(data, errorCode, errorMessage) {
        var jsonObject = JSON.parse(data.body);
        var errMsg = jsonObject.error.message.value;
        alert(errMsg);
    }
});
4

1 回答 1

0

使用 SP.RequestExecutor,您必须确保正确使用 appweburl 和 hostweburl 参数。例如,我假设您使用的“baseUrl”值实际上是您从 SharePoint 收到的 appweburl。

此外,您需要将目标 url(hostweburl)附加到您的 URL 字符串中。

虽然这涉及更新,但在这里查看我的帖子可能会很有用。

于 2013-07-17T10:28:56.733 回答