How to programmatically disable/enable Order Now and Add to Cart buttons in the ServicePortal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2025 09:41 AM
I made a function that works well for toggling the Add To Cart and Order Now buttons during my onSubmit():
function toggleSubmitButtons(state) {
var index;
var cartBtns = document.getElementsByName('add_to_cart');
for (index = 0; index < cartBtns.length; index++) {
cartBtns[index].style.display = state;
}
var saveBtns = document.getElementsByName('save_item');
for (index = 0; index < saveBtns .length; index++) {
saveBtns[index].style.display = state;
}
this.document.getElementsById('submit-btn').style.display = state;
}
State == 'none' or '' for disable/enable.
This works but seems to give me the warning: This catalog client script is not VA supported due to the presence of the following variables in the script: ... ... ..
It does not like the DOM manipulation.
I found many links explaining that they can be disabled.. such as this: https://www.servicenow.com/community/itsm-forum/how-to-hide-quot-order-now-quot-button-for-a-one-cat...
How can I access those values via g_form or some other mechanism that won't give me the VA support warning? I want to programmatically enable/disable 'Add to Cart' and 'No Order Now'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2025 03:07 PM
Hi @colleyloyej,
You need to use g_form.getFormElement().
Example script that you created. I just randomly made adjustments.
Test and correct it to make it work.
function toggleSubmitButtons(state) {
var cartBtns = g_form.getFormElement().querySelectorAll('[name="add_to_cart"]');
cartBtns.forEach(function(btn) {
btn.style.display = state;
});
var saveBtns = g_form.getFormElement().querySelectorAll('[name="save_item"]');
saveBtns.forEach(function(btn) {
btn.style.display = state;
});
var submitBtn = g_form.getFormElement().querySelector('#submit-btn');
if (submitBtn) {
submitBtn.style.display = state;
}
}
Let me know if it worked.
Regards,
Vikas K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2025 06:25 PM
Hi Vikas: Thanks I'll give that try tomorrow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 06:38 AM
Hi Vikas: I tried that but still get the warning: This catalog client script is not VA supported due to the presence of the following variables in the script: g_form.getFormElement.QuerySelector.
Also it seems to give a console error: Cannot read properties of undefined (reading 'querySelector')
Does Virtual Agent support really mean much? I don't even think we use it much if at all.