Для 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>
