以编程方式启用SharePoint列表中的内容审批(审核)

时间:2014-06-18 15:51:28

标签: sharepoint sharepoint-list csom sharepoint-online

我正在编写一个创建自定义事件列表的应用程序。

我想在创建列表时启用内容审批(在后端也称为审核)。

这是我的列表创建代码的样子。

    function createList(listToCreate)
{
    // Create a SharePoint list with the name that the user specifies.
    var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
    var hostContext = new SP.AppContextSite(currentContext, hostUrl);
    var hostweb = hostContext.get_web();
    var listCreationInfo = new SP.ListCreationInformation();

    //title the list
    listCreationInfo.set_title(listToCreate);

    //set the base type of the list
    listCreationInfo.set_templateType(SP.ListTemplateType.events);

    var lists = hostweb.get_lists();
    //use the creation info to create the list
    var newList = lists.add(listCreationInfo);

    var fieldCollection = newList.get_fields();

    //add extra fields (columns) to the list & any other info needed.
    fieldCollection.addFieldAsXml('<Field Type="User" DisplayName="Requester" Name="Requester" />', true, SP.AddFieldOptions.AddToDefaultContentType);
    fieldCollection.addFieldAsXml('<Field Type="User" DisplayName="Manager" Name="Manager" />', true, SP.AddFieldOptions.AddToDefaultContentType);
    fieldCollection.addFieldAsXml('<Field Type="Boolean" DisplayName="Approved" Name="Approved" />', true, SP.AddFieldOptions.AddToDefaultContentType);

    //Attempting to enable moderation. This doesn't seem to have any effect.
    newList.set_enableModeration(true);

    currentContext.load(fieldCollection);
    currentContext.load(newList);
    currentContext.executeQueryAsync(onListCreationSuccess, onListCreationFail);     
}

function onListCreationSuccess() {
    alert("We've created a list since one didn't exist yet. Look in the site that hosts this app for the list." );
}

function onListCreationFail(sender, args) {
    //alert("We didn't create the list. Here's why: " + args.get_message());
}

不幸的是.set_enableModeration(true);似乎无效。我没有收到任何错误,但当我查看使用此代码创建的列表的设置时,我看到: enter image description here

因此,内容审批显然未通过我正在使用的方法启用。

1 个答案:

答案 0 :(得分:2)

要使用SP.List.enableModeration Property设置Content Approval,必须调用SP.List.update() Method,如下所示:

list.set_enableModeration(true);
list.update();