Restrict the request submission if requested for already submitted one

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 11:54 AM
Hi All,
Having a requirement that,
Need to restrict the request submission, if there is already a request submitted by the same requested for and the for the same selected course.
need suggestion to achieve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 12:13 PM
Hello @Community Alums ,
You can create a catalog client scritp on submit type.
In that, you can call the script include and in script include glide the table and check the current requested for with same course already present or not. If it is presented then just return false;
Please like this if this will help you.
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2024 04:56 AM
Thanks for the swift response,
Can you suggest any reference script to validate the same. That will be much helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 01:01 PM
Hello @Community Alums ,
Best approach would be to create a Catalog client script. It can be onChange or onSubmit. I mentioned below the code base for onChange catalog client script.
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
g_form.hideFieldMsg('requested_for', true);
if (newValue == '')
return;
var ga = new GlideAjax('AjaxFunctions');
ga.addParam('sysparm_name', 'checkUserRequest');
ga.addParam('sysparm_user', newValue); // User
ga.addParam('sysparm_item', g_form.getUniqueValue()); // Item
ga.getXMLAnswer(function(answer) {
if (answer && answer != 'none') {
var msg = 'This person already has an open Request(s) for this item: ' + answer;
g_form.showFieldMsg('requested_for', msg, 'error', false);
}
});
}
Script Include: It is Client Callable = true and accessible from all application scopes.
var AjaxFunctions = Class.create();
AjaxFunctions.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkUserRequest: function() {
var user = this.getParameter('sysparm_user');
var item = this.getParameter('sysparm_item');
var requests = [];
var ritm = new GlideRecord('sc_req_item');
ritm.addActiveQuery();
ritm.addQuery('request.requested_for', user);
ritm.addQuery('cat_item', item);
ritm.query();
while (ritm.next()) {
requests.push(String(ritm.number));
}
if (requests.length > 0)
return requests.join(', ');
return 'none';
},
type: 'AjaxFunctions'
});
If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.
Regards,
Shubham