How Restrict the User to only one Request per catalog item?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2020 10:57 AM
how can we restrict the user to only one request per catalog item if he has already an existing open request for that catalog item.
for example
If a user has an open request on catalog item 'X' again he is trying to raise the request for the same catalog item i want to restrict him from raising the request in such case how is it possible
- Labels:
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2020 06:04 AM
Create the script include as provided by Brad:
var RITMLookup = Class.create();
RITMLookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRITM: function() {
var answer = '';
var catitem = this.getParameter('sysparm_catitem');
//var user = this.getParameter('sysparm_user');
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item', catitem);
ritm.addQuery('state', '1')
//ritm.addQuery('request.requested_for', user);//if you are populating the REQ requested_for from the cat item
ritm.query();
if(ritm.next()) {
answer = ritm.number;
}
return answer;
},
type: 'RITMLookup'
});
And client script set to Desktop (this will work in the back-end):
function onSubmit() {
var catitem = g_form.getUniqueValue();
var user = g_form.getValue('requested_for');//assuming you have a reference variable with this name
var ga = new GlideAjax('RITMLookup'); //Name of the Script Include
ga.addParam('sysparm_name','getRITM'); //name of function in script include
ga.addParam('sysparm_catitem', catitem);
ga.addParam('sysparm_user', user);
ga.getXMLWait();
var answer = ga.getAnswer();
if (answer != ''){
alert("The requested for user already has pending request " + answer + " in the system. Only one request for a person may be open at a time.");
return false;
}
}
For the Service Portal, create a new onSubmit Catalog Client script set to UI Type Mobile/Service Portal:
function onSubmit() {
if (g_scratchpad.isFormValid)
return true;
var catitem = g_form.getUniqueValue();
var user = g_form.getValue('requested_for');//assuming you have a reference variable with this name
var ga = new GlideAjax('RITMLookup'); //Name of the Script Include
ga.addParam('sysparm_name','getRITM'); //name of function in script include
ga.addParam('sysparm_catitem', catitem);
ga.addParam('sysparm_user', user);
ga.getXMLAnswer(setAnswer);
return false;
function setAnswer(answer){
if (answer != ''){
alert("The requested for user already has pending request " + answer + " in the system. Only one request for a person may be open at a time.");
return false;
}
var actionName = g_form.getActionName();
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
For a more detailed explanation, please refer to:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2020 08:39 AM
you can use this approach as onSubmit with Asynchronous won't help
Also you cannot use getXMLWait() in portal
1) create a hidden variable on your catalog item of type string with highest order
2) hide this using UI policy onLoad
3) write onLoad catalog client script and use GlideAjax to set this variable value with true or false based on whether script include returns true or false if RITM present for this user
4) then in onSubmit you can check what is the variable value and based on that stop the form submission if value is true
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2020 12:09 AM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark appropriate answer as correct & helpful to close the thread.
If not, please let us know if you need some more assistance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2020 01:19 PM
Hi
If you users are only allowed to use two step checkout, where you need to put the item to the cart, I would like to prevent that.
Way before it is even possible to checkout the cart.
Maybe you can do so by creating a BEFORE INSERT BR on the sc_cart table.
Let me know if that answered your question and mark my answer as correct and helpful.
BR
Dirk

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2020 10:14 AM
Hi
Do you have any update on this?
BR
Dirk