如何解决SHAREPOINT - 限制重复输入
伙计们需要以下场景的支持 我有一份带有日期和时间的预订清单。我想按日期和时间限制重复条目 我已经尝试了其余的 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,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('{',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}')
}
},errorThrown) {
alert(textStatus);
}
})
return check;
}
</script>
解决方法
您可以使用以下代码限制重复输入:
<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,errorThrown) {
alert(textStatus);
}
})
return check;
}
</script>
注意:您需要更改以下内容:
- 在
var DateId = $("input[title='Date_Req']").val()
中,将“Date_Req”更改为您的日期列名称; - 在 $.ajax() 中,将 url 部分中的列表标题和列名称更改为您的名称
<script type="text/javascript">
function PreSaveAction() {
var check = false;
//var listid = _spPageContextInfo.pageListId.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 + "'",headers: {
"accept": "application/json;odata=verbose",jqXHR) {
var count = data.d.results.length;
if (count < 1) {
check = true;
} else {
alert('Dear Employee,there is no slot available during this period');
}
},errorThrown) {
alert(textStatus);
}
})
return check;
}
</script>```
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。