Hide/Disable "Add to Cart" on portal based on Yes/No variable

Service Manager
Kilo Guru

Hi,

I need help to hide/disable "Add to cart" for a specific catalog item. We have a Yes/No variable and if variable is answered as No only then hide "Add to Cart" button.

find_real_file.png

Thanks

1 ACCEPTED SOLUTION

Hi,

just use it in onchange

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(g_form.getValue(have_you) == 'No')
{
if(window == null){
        // for portal
        var z = this.document.getElementsByClassName("btn btn-default sc-btn form-control ng-scope");
        z[0].style.display = 'none';
    }
    else{
        // for native
        gel('oi_add_to_cart_button').style.display = 'none';
    }
}

else{
if(window == null){
        // for portal
        var z = this.document.getElementsByClassName("btn btn-default sc-btn form-control ng-scope");
        z[0].style.display = '';
    }
    else{
        // for native
        gel('oi_add_to_cart_button').style.display = '';
    }
}
}

Regards
Ankur

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

View solution in original post

12 REPLIES 12

Thanks for the quicks response.

When I tried your script it wasn't working and throws below error

find_real_file.png

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(g_form.getValue(have_you) == 'No')
{
document.getElementById("widget-sc-cat").style.display = 'none'; // hide
}
//you can get the id of your button by inspecting it.
else{
document.getElementById("widget-sc-cat").style.display = ''; // show
}
}

 

Thanks

Have you set 'isolate' checkbox false in your script ? That revokes DOMs to work and throws error. Can you confirm that?

find_real_file.png

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Yes, I confirmed that.