How to hide submit button when items are present in the cart in employee service center portal form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 05:26 AM - edited 08-22-2024 05:43 AM
Hi Community,
We have a requirement, that submit button should disappear when items are not present in the cart, if there are no items in the cart then only it should visible.
appreciated for the quick response.
Thanks,
Shrinivasprasad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 05:44 AM
@shrinivasprasa1 You need a combination of a GlideAjax call + DOM manipulation to achieve this. Using GlideAjax, and a server side script include you can check if there any records for the user in sc_cart table. If the count is grater than 0 then you can use the DOM manipulation via your client script to show the submit button or hide it.
For DOM manipulation, you can take the reference of this community post https://www.servicenow.com/community/developer-forum/hide-disable-quot-add-to-cart-quot-on-portal-ba...
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 07:13 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 08:06 AM
@shrinivasprasa1 Here is the sample code to check
Client script.
function onLoad() {
// Call a Script Include using GlideAjax to check if there are items in the cart
var ga = new GlideAjax('CartCheck');
ga.addParam('sysparm_name', 'checkCart');
ga.getXMLAnswer(function(response) {
var itemsInCart = parseInt(response);
// If there are no items in the cart, hide the submit button
if (itemsInCart === 0) {
// Hide the submit button by setting its display style to 'none'
document.getElementById('oi_order_now_button').style.display = 'none';
document.getElementById('oi_request_button').style.display = 'none';
}
});
}
var CartCheck = Class.create();
CartCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkCart: function() {
var cart = new GlideRecord('sc_cart');
cart.addQuery('user', gs.getUserID());
cart.addActiveQuery();
cart.query();
if (cart.next()) {
var cartItem = new GlideRecord('sc_cart_item');
cartItem.addQuery('cart', cart.sys_id);
cartItem.addActiveQuery();
cartItem.query();
return cartItem.getRowCount();
}
return 0;
}
});
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 06:14 AM
Hi @Sandeep Rajput ,
Thanks for the reply, i have written onload client script as below but it is not working, i have added the items in the cart stiil the submit button is showing us in the form.
Thanks,
Shrinivasprasad