How to restrict users to place only 1 order per catalog item?

Younes Choukri1
Tera Contributor

I'd to know how to restrict a client to allow him to only place one order per catalog item?

Any tips are welcome, I'm looking to apply a client script and a script include.

Thank you

4 REPLIES 4

Chetan Mahajan
Kilo Sage
Kilo Sage

Hi Younes,

                       Refer to this thread there are 2-3 approaches How Restrict the User to only one Request per catalog item?

 

 

SumanthDosapati
Mega Sage
Mega Sage

Hi @Younes Choukri 

> Have a 'requested for' variable in your catalog item 

> Write an On Change client script on that field and a script include as below.

Client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}

	g_form.hideFieldMsg('requested_for', true); //give your variable name

	if(oldValue != newValue){
		var ga = new GlideAjax('Script_Include_Name');  //give your client callable script include name
		ga.addParam('sysparm_name', 'checkDuplicate');
		ga.addParam('sysparm_user', newValue);
                ga.addParam('sysparm_item', g_form.getUniqueValue());
		ga.getXML(callback);
		function callback(response) {
			var answer = response.responseXML.documentElement.getAttribute("answer");
			if (answer.toString() == 'yes') {
				g_form.clearValue('requested_for', true); //give your field name
				g_form.showFieldMsg('requested_for', 'User already submitted a request for this catalog item', 'Error');
			} 
		}
	}
}

 

Script Include :

checkDuplicate: function() {
		var user = this.getParameter('sysparm_user');
		var item = this.getParameter('sysparm_item');

		var gr = new GlideRecord('sc_req_item');
                gr.addQuery('cat_item', item);
                gr.addQuery('requested_for', user);
		gr.query();
                if(gr.next())
{
 return "yes";
}
else 
{

		return "no";
	},

 

Mark as correct and helpful if it solved your query.

Regards,

Sumanth

Younes Choukri1
Tera Contributor

I found an easier way to do this, however this would apply to all catalogs created henceforth:

 

Procedure

  1. Navigate to All > System Definition > Choice Lists.
  2. Search for the table sc_cart_item and the element quantity. The existing quantity choices appear.
  3. Add quantity choices, modeling them after the existing ones.
    Quantity element values

    To reduce the quantities available for catalog items, delete the relevant quantity records. For example, to reduce the quantity range to 1-3, delete the records for 4 and 5.

    To restrict the roles allowed to change quantities, edit the List of roles (comma-separated) that can use the quantity selector in the shopping cart (glide.sc.allow.quantity) service catalog property. For example, you can limit this ability to the admin and catalog_admin roles.

     

    Thank you for your assistance guys

By doing so, you may not add multiple catalog items into cart as well. For suppose you cannot add 5 different catalog items one each into cart and submit the request. Regards, Sumanth