1

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

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

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

    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);没有效果。我没有收到任何错误,但是当我查看使用此代码创建的列表的设置时,我看到: 在此处输入图像描述

所以内容批准显然没有通过我使用的方法启用。

4

1 回答 1

2

为了Content Approval使用SP.List.enableModeration 属性进行设置,必须调用SP.List.update() 方法,如下所示:

list.set_enableModeration(true);
list.update();
于 2014-06-18T23:22:53.193 回答