How Restrict the User to only one Request per catalog item?

Gowtham Kodali
Tera Contributor

 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

15 REPLIES 15

Brad Bowman
Kilo Patron
Kilo Patron

You need to do this at the catalog client script level since submitting a request creates an REQ and RITM, and you want to properly prevent submission of both of these while letting the user know why they can't submit the request.  You need to capture the current user to pass to the server script.  Ideally you will have a mandatory requested_for variable on each catalog item, then you would also want a business rule, or run script on each workflow to populate the REQ requested_for from this variable.   

If you're not using Service Portal, you can create an onSubmit Catalog Client Script that looks similar to this (getXMLWait doesn't work in Portal to prevent submission since it's asynchronous).  You would have to create this script in each catalog item, or put it in a variable set (doesn't need to contain any variables), then add the variable set to each item.

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;
   }
}

Next, create a Script Include with the same name used in the GlideAjax call, ensuring that the Client callable box is checked.  Your script will look something like this

var RITMLookup = Class.create();
RITMLookup.prototype = Object.extendsObject(AbstractAjaxProcessor, { 
 
  getRITM: function() { 
   car 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('request.requested_for', user);//if you are populating the REQ requested_for from the cat item
   //or use the next line instead
   //ritm.addQuery('opened_by', user);
   ritm.query();
   if(ritm.next()) {
    answer = ritm.number;
   }
   return answer;
  },
        
type: 'RITMLookup'
});

Hi  I am getting an Error message in console of Portal page that getXMLwait is no longer supported any other alternative for this,

 

mr18
Tera Guru
Tera Guru

Try below before insert Business Rule on Requested item table as below

var gr = new GlideRecord("sc_req_item");
gr.addQuery("cat_item",current.cat_item);
gr.addEncodedQuery("stateNOT IN3,4"); //state is not one of closed or cancelled
gr.query();
while(gr.next()) {
current.setAbortAction(true);
gs.addErrorMessage("User has already open request for this catalog item");
}

@Gowtham Kodali let me know if it resolved your issue

No RITM is not Creating but REQ##### is creating