We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Limit Quantity to 2 on the order guide for specific catalog item

Harika Thota
Tera Guru

Hi ,

 

I want to limit quantity to 2 on the order guide for specific catalog item.

HarikaThota_0-1770758290527.png

 

Thanks in Advance!

Harika

 

8 REPLIES 8

Ankur Bawiskar
Tera Patron

@Harika Thota 

did you configure the quantity for that item?

Define item quantity choices 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

lauri457
Tera Sage

This is the snippet in the server code that collects the choices for quantity. If you look at the html template you'll notice that all the items will use the same array of choices.

function getQuantityChoiceList() {
	var clGenerator = new GlideChoiceList();
	var choiceListQuantity = clGenerator.getChoiceList("sc_cart_item", "quantity");
	var choicelistQuantityData = [];
	for (var i = 0; i < choiceListQuantity.size(); i++) {
		var choice = choiceListQuantity.get(i);
		if (!isNaN(choice.getValue()))
			choicelistQuantityData.push({
				value: parseInt(choice.getValue()),
				label: choice.getLabel()
			});
	}
	return choicelistQuantityData;
}

Which means you will have to edit where the options come for the ngRepeat directive. E.g something like this

<select id="catItemQuantity" ng-change="updateQuantity(item)" class="scBasicSelect" ng-model="item.quantity">
     <option ng-repeat="num in item.quantitylist" <!-- can't use 'static' choiceListQuantity --> value={{::num.value}}>{{::num.label}}</option>
</select>
item = $sp.getCatalogItem(itemData); 
//add logic here to create your choicelist in some way. Item object has plenty of information about the catalog item in question
if (item.sys_id == "e56b521883313210557ff0d6feaad322") {
	item.quantitylist = [{ value: 1, label: "1" }, { value: 2, label: "2" }]
} else {
	item.quantitylist = data.choiceListQuantity
}
item.quantity = item.quantitylist[0].label

lauri457_1-1770788204809.pnglauri457_2-1770788242961.png

 

 

Hi Lauri,

 

The script which you referring is from the OOB SC Order guide but this widget is High risk file. Which will effect in the future upgrades.

 

Despite what the community often says, customization only adds risk as in adds to the potential of negative outcomes it's not an automatic no-no. If you have good governance then it is fairly simple to keep the widget "up-to-date" during upgrades. The problems arise when nobody knows why something was done and who owns it. The platform exists to support the processes at your org, granted they should be somewhat logical and follow good ux practices.

 

There are many ways to achieve the same effect. What you do depends on the implementation and how established and rigid your catalog practice is. People typically resist change so I can predict business would want this widget change rather than adopt using e.g bundled models or whatever. 

 

As said the choice list is pulled from the dictionary so you can't alter it item by item as it uses the same choicelist for all items. You can for example remove the quantity option for the item and get the quantity in the describe needs part.