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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2022 06:23 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2022 06:29 AM
Hi Younes,
Refer to this thread there are 2-3 approaches 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
‎06-04-2022 08:55 AM
Hi
> 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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2022 06:02 PM
I found an easier way to do this, however this would apply to all catalogs created henceforth:
Procedure
- Navigate to All > System Definition > Choice Lists.
- Search for the table sc_cart_item and the element quantity. The existing quantity choices appear.
- Add quantity choices, modeling them after the existing ones.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2022 09:59 PM