Hide add to cart and order now button from service portal

TMKAM
Tera Contributor

I have create variable with 2 option and below are the scenario i want to achieve.

Scenario 1

When i choose option 1 variable name (u_option1) default the add to cart and order now button already loaded.

Scenario 2

When i choose option 2 variable name (u_option2) the add to cart and order now button must hide.

I attach the screenshot for your reference and is there scripts or option I can do that.

Thank you.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

for showing/hiding the add to cart and order now button via script would require DOM manipulation which is not recommended.

if you still require then use this onChange script on that variable

I have shared solution here 2 years ago; enhance it for your requirement

Ensure Isolate Script field is set to False for this client script

find_real_file.png

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	if(newValue == 'u_option2'){
		// hide
		this.document.getElementsByClassName('btn btn-default sc-btn form-control ng-scope')[0].style.display = 'none';
		this.document.getElementsByClassName('btn btn-primary btn-block ng-binding ng-scope')[0].style.display = 'none';
	}
	else{
		// show
		this.document.getElementsByClassName('btn btn-default sc-btn form-control ng-scope')[0].style.display = '';
		this.document.getElementsByClassName('btn btn-primary btn-block ng-binding ng-scope')[0].style.display = '';
	}

	//Type appropriate comment here, and begin script below
}

Regards
Ankur

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

View solution in original post

10 REPLIES 10

Dear Smudge,

thank you for your information and your expertise.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

for showing/hiding the add to cart and order now button via script would require DOM manipulation which is not recommended.

if you still require then use this onChange script on that variable

I have shared solution here 2 years ago; enhance it for your requirement

Ensure Isolate Script field is set to False for this client script

find_real_file.png

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	if(newValue == 'u_option2'){
		// hide
		this.document.getElementsByClassName('btn btn-default sc-btn form-control ng-scope')[0].style.display = 'none';
		this.document.getElementsByClassName('btn btn-primary btn-block ng-binding ng-scope')[0].style.display = 'none';
	}
	else{
		// show
		this.document.getElementsByClassName('btn btn-default sc-btn form-control ng-scope')[0].style.display = '';
		this.document.getElementsByClassName('btn btn-primary btn-block ng-binding ng-scope')[0].style.display = '';
	}

	//Type appropriate comment here, and begin script below
}

Regards
Ankur

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

Dear Ankur,

I have use your scripts in the catalog scripts and it is working as expected.

thank you.

Glad to know.

Please mark response helpful as well.

Regards
Ankur

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

Dear Ankur,

Is it possible to hide the word "Approval is Precondition"? i attach the screenshot for your reference.

thank you