男生需要以下场景的支持--我有一个日期和时间的预订列表。我想限制重复条目的日期和时间,我已经尝试了其余的Api代码,但它不起作用。请支持我下面的代码
我试着用一个条件..。我需要检查两个条件
请支持
<script src="/Departments/WDCI/UIJP/PublishingImages/jquery-1.12.4.js" type="text/javascript"></script><script type="text/javascript">
function PreSaveAction() {
var check = false;
var listid = _spPageContextInfo.pageListId.replace('{', '').replace('}', '');
var DateId = $('input[id*="Date_Req"]');
$.ajax({
//replace the rest api to filter items based on your files
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists(guid'" + listid + "')/items?$select=ID,Req_Date,Req_Time,Title&$orderby=ID desc&$filter=Date_Req eq + DateId + ",
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 < 2) {
check = true;
} else {
alert('Dear Employee,This Calander Year you have already applied for two Job Positions.So you are eligible to apply next year only');
ddwrt:GenFireServerEvent('__commit;__redirect={/SiteAssets/Thank%20You.aspx}')
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
})
return check;
}
</script>
<script src="jquery-1.12.4.js" type="text/javascript">
</script><script type="text/javascript">
function PreSaveAction() {
var check = false;
var listid = _spPageContextInfo.pageListId.replace('{', '').replace('}', '');
var DateId = $('input[id*="Date_Req"]');
$.ajax({
//replace the rest api to filter items based on your files
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists(guid'" + listid + "')/items?$select=ID,Req_Date,Req_Time,Title&$orderby=ID desc&$filter=Date_Req eq + DateId + ",
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 < 1) {
check = true;
} else {
alert('Dear Employee,there is no slot available during this period');
ddwrt:GenFireServerEvent('__commit;__redirect={/SiteAssets/Thank%20You.aspx}')
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
})
return check;
}
</script>发布于 2021-03-29 07:06:03
<script type="text/javascript">
function PreSaveAction() {
var check = false;
//var listid = _spPageContextInfo.pageListId.replace('{', '').replace('}', '');
var DateId = $("input[Title*='Req_Date']").val();
var TimeID= $("select[Title*='Req_Time'] option:selected").text();
alert(DateId);
alert(TimeID);
$.ajax({
//replace the rest api to filter items based on your files
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists//GetByTitle('Discussion2')/items?$select=ID,Req_Date,Req_Time,Title&$orderby=ID desc&$filter= Req_Date eq '" + DateId + "' and Req_Time eq '" + TimeID + "'", 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 < 1) {
check = true;
} else {
alert('Dear Employee,there is no slot available during this period');
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
})
return check;
}
</script>```发布于 2021-03-25 08:54:09
可以使用以下代码限制重复条目:
<script type="text/javascript">
function PreSaveAction() {
var check = false;
//var listid = _spPageContextInfo.pageListId.replace('{', '').replace('}', '');
var DateId = $("input[title='Date_Req']").val();
alert(DateId);
$.ajax({
//replace the rest api to filter items based on your files
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists//GetByTitle('List0325')/items?$select=ID,Date_Req,Title&$orderby=ID desc&$filter=Date_Req eq '" + DateId + "'",
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 < 1) {
check = true;
} else {
alert('Dear Employee,there is no slot available during this period');
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
})
return check;
}
</script>注意:您需要更改以下内容:
var DateId = $("input[title='Date_Req']").val(),将"Date_Req“更改为日期列名;中的
其结果是:

https://stackoverflow.com/questions/66778823
复制相似问题