- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2020 03:01 PM
Hi Dev community!
I am trying to disable or grey out the 'Add to Cart' button in a service catalog item once the shopping cart total reaches >= 5 items. May I get assistance what is the syntax to disable the 'Add to Cart' button, please?
I have tried the following and they all do not work:
1.
document.getElementById('sc_add_to_cart_button').style.display='none';
2.
var addtocart = document.getElementById('add_to_cart_button');
addtocart.style.display='none';
3.
$('oi_add_to_cart_button').disabled=true;
My PDI is a New York version.
Thanks in advance!
Best regards,
Harriet
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2020 03:39 PM
Use below script to hide cart.
Make sure that you do GlideRecord in script include and call script include from your client script.
var user_id = g_user.userID;
var sccart = new GlideRecord('sc_cart_item');
sccart.addQuery('cart.user',user_id);
sccart.query();
var count = 0;
while(sccart.next()){
count = count+parseInt(sccart.quantity);
}
if(count >5 ){
var cart = document.getElementById('order_and_cart_v2');
cart.style.display='none';
}
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2020 03:39 PM
Use below script to hide cart.
Make sure that you do GlideRecord in script include and call script include from your client script.
var user_id = g_user.userID;
var sccart = new GlideRecord('sc_cart_item');
sccart.addQuery('cart.user',user_id);
sccart.query();
var count = 0;
while(sccart.next()){
count = count+parseInt(sccart.quantity);
}
if(count >5 ){
var cart = document.getElementById('order_and_cart_v2');
cart.style.display='none';
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2020 07:48 AM
Thank you, Sachin! It did not work for me, but I think I'm not able to see the true end result since ours behaves differently due to maybe some kind of business rules. Anyway, I appreciate your help and response!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2022 09:18 AM
hi,
i have the same requirement how can i call this script include into client please, and what should i modify this line
var cart = document.getElementById('order_and_cart_v2');
should i put yhe name of the button in getElementById