Newbie to sharepoint , I have a sharepoint list with Date(Calender) field. Iam looking at a way to restrict only 4 entries per day in the list.
Example:
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
Any suggestions or leads will be helpful.
For SharePoint 2013 or online classic view, you could use PreSaveAction
.
Sample code:
<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>