每天仅限制共享点4个条目

时间:2019-04-09 20:30:58

标签: sharepoint sharepoint-designer

新手要共享点,我有一个带有Date(Calender)字段的共享点列表。我正在寻找一种方法来限制列表中每天只有4个条目。

示例:

Date        desc
01/01/2018  entry1
01/01/2018  entry2
01/01/2018  entry3
01/01/2018  entry4

or 

Date       start   end    desc
01/01/2018 10:00   10:15  entry1
01/01/2018 10:15   10:30  entry2
01/01/2018 10:30   10:45  entry3
01/01/2018 10:45   11:00  entry4

任何建议或线索都会有所帮助。

1 个答案:

答案 0 :(得分:0)

对于SharePoint 2013或联机经典视图,可以使用PreSaveAction

示例代码:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
    <script type="text/javascript">
    function PreSaveAction() {
        var check = false;
        var listid = _spPageContextInfo.pageListId.replace('{', '').replace('}', '');
        var today = new Date();
        var nextday = moment(today).add(1, 'days');
        today = moment(today).format("YYYY-MM-DD");
        var currentDate = today + 'T00:00:00.000Z';
        nextday = moment(nextday).format("YYYY-MM-DD");
        var nextDate = nextday + 'T00:00:00.000Z';
        var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists(guid'" + listid + "')/items?$filter=Created ge datetime'" + currentDate + "' and Created le datetime'" + nextDate + "'";
        console.log(url);
        $.ajax({
            url: url,
            type: 'GET',
            async: false,
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
            },
            success: function (data, textStatus, jqXHR) {
                var count = data.d.results.length;
                if (count < 4) {
                    check = true;
                } else {
                    alert('Over Max items');
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(textStatus);
            }
        })
        return check;
    }
    </script>

enter image description here