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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

For that you would require DOM manipulation but that is not recommended.

If you still want to go ahead refer these link(s) for sample script

How to disable Order Now and Add to Cart buttons based on some actions when user is submitting the r...

To Hide "Add to Cart " & "Order Now " Button using client script

Regards
Ankur

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

Hi,

I tried below script but it didn't worked. actually we want to have the script on Onchange and it gives the error.

find_real_file.png

 

function onLoad() {


var cart = document.getElementById('widget-sc-cat');


cart.style.display='none';


}

 

Thanks

Hi,

DOM won't work in portal

where are you running this?

Regards
Ankur

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

I am trying to hide the "Add to cart" on Service portal.

 

Thanks