The CreatorCon Call for Content is officially open! Get started here.

how to hide the button add to cart only in backend through client script

Fdeveloper
Kilo Guru

Hi,

i should hide the button add to cart only in the backend in the portal the button should be visible , i try it to check 

Hide 'Add to Cart' to true not working and i try it No cart it works the button is hiding but it also hidding from the portal 

i should hide the button through client script any suggestion please to resolve this issue 

19 REPLIES 19

Allen Andreas
Administrator
Administrator

Hi,

If you've tried the other methods hide the add to cart as mentioned below and elsewhere in the platform/documentation, then the next thing would be via DOM manipulation.

This would only be possible via DOM manipulation which isn't recommended or best practice however, it can still be done.

Please refer to this post which shows how to do it (it's based on a variable being a certain value, but the main point is, the major part of the script is what you want anyway).

You would need to ensure that the "Isolate script" checkbox on the client script form is set to false (if the field is not present on the form, add it, then set it to false).

https://community.servicenow.com/community?id=community_question&sys_id=de801b32db38e410b1b102d5ca96...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi @Allen Andreas ,

don't work for me i try it this solution i still see the button even isolate script is false,

i use client script not catalof client script

function onLoad() {

        var catSysID = g_form.getUniqueValue(); 
	    alert(catSysID);
		
        var ajax = new GlideAjax('test'); 
        ajax.addParam('sysparm_name', 'getServiceCatalog'); 
        ajax.addParam('sysparm_cat_sys_id', catSysID); 
        ajax.getXMLAnswer(function(answer) {
            //if (answer.length > 0) {
			if (answer == 'company') {
               // alert('service catalog name:' + answer);
				//document.getElementById('add_to_cart_button').style.display = 'none';
	      gel('oi_add_to_cart_button').style.display = 'none';
            }
			
        });


Hi,

I would recommend trying it without your GlideAjax, just to confirm it all works, then add in your GlideAjax. You're introducing an extra component that I wasn't covering above and you didn't specify that you were using in your original post.

So let's confirm what I've given actually works, in general, then, from there, you can add in your GlideAjax and then troubleshoot that with appropriate log statements, etc.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

@Allen Andreas ,

even i don't use GlideAjax don' work i dont know why i try to create another client script onload the table sc_cat_item , isolate script is false , type is desktop 

function onLoad() {

// var cart = document.getElementById('order_and_cart_v2');

  cart.style.display='none'; don't work ;
  // document.getElementById('add_to_cart_button').style.display = 'none'; don't work
  $('oi_add_to_cart_button').hide(); don't work
 	




   
}