How to limit the number of requests (not more than 2) for a particular catalog item based on dropdown variable select

robinpaul
Kilo Contributor

How to limit the number of requests (not more than 2) for a particular catalog item based on dropdown variable select

currently , there is a catalog item "Reserving laptops/Desktops" . There is a variable(select box) called "location" with the choices a) EMEA b) Apac c)Others

My Requirement is like this :

If the User selects the location as EMEA OR Apac ,then the particular user will be able to submit the 2 requests only for this catalog item.(user need not allow to submit the 3rd request for this item)

User will be   able only to submit the 3rd request,when the state of any one of the 2 requests(which are already submitted by user) is closed/cancelled.

If the User selects the location as "Other" ,then there is no restrictions to submit the requests for this catalog item

How can i acheive this one.

Any help would be appreciated.Thanks in Advance.

1 ACCEPTED SOLUTION

Hi Robin,


I think we have it.


Here is the script include:


var checkCount = Class.create();


checkCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  theCount : function() {



  var user = this.getParameter('sysparm_user');


  var catItem = this.getParameter('sysparm_item');


  var location = this.getParameter('sysparm_loc'); //this is your location field value received from the requested item


  var encQuery = 'sc_item_option.item_option_new.name=location^sc_item_option.value='+location; //where location is the name of your choice list



  var ri = new GlideRecord('sc_item_option_mtom'); //checking the variable table


  ri.addEncodedQuery(encQuery);


  ri.addQuery('request_item.request.requested_for', user); //checking for the user


  ri.addQuery('request_item.active', 'true'); //checking that the requested item is active


  ri.addQuery('request_item.cat_item', catItem); //checking the catalog item


  ri.query();



  var count = ri.getRowCount();


  return count;


},


  type: 'checkCount'


});


And in your catalog client script, add the following lines:


ga.addParam("sysparm_loc", v_location); //send value of location to the script include


change       if (answer > 2) {


to       if (answer > 3) {   or to whatever other number that suits your need.



Leave your conditions in the catalog client script as they are so that the script include checks against that specific choice.


harel


please mark as correct or helpful based on needs


View solution in original post

10 REPLIES 10

robinpaul
Kilo Contributor

Hi Harel,



Thanks for giving quick and correct reply. I tested the above code and the script works very well.


Thank you ..