Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to Hide "Order Now" button on the Portal at Runtime

G24
Kilo Sage

Hello.  I read the post here but that solution is not working for me.

When my code runs, I get the "this.jQuery is defined" alert message, but still the button is not hidden.

 

Thoughts on what might be going wrong here?  Thank you.

 

S1.png

 

I want to do this because if our users answer certain questions the wrong way on a Catalog Item, we don't want them to even be able to submit it.

1 ACCEPTED SOLUTION

G24
Kilo Sage

I was able to get this working finally, using a different this.jQuery() query:

function onCondition() {
	if (this.jQuery){
		//alert("1");
		//this.jQuery("btn-primary").hide(); //Did NOT work for me.  I have no elements of type "btn-primary".
		//this.jQuery("#btn-primary").hide(); //Did NOT work for me.  I have no elements with id "btn-primary".
		
		//this.jQuery(".btn-primary").hide(); //Any element with class == .btn-primary.  This did work for me.
		this.jQuery("button[name='submit']").hide(); //Any button element where 'name' = 'submit'.  Works also.
		//alert("2");
	}
}

View solution in original post

9 REPLIES 9

Kieran Anson
Kilo Patron

Rather than trying to hide the button which could lead to a poor UX as the user may feel the form is broken and raise an incident, you could use an onSubmit catalog client script to abort the submit process and display a helpful message explaining WHY they're not yet allowed to submit the form. You also avoid problematic DOM manipulation which could break on upgrading the instance 

Actually, I agree with you, @Kieran Anson but I would still like an answer to this specific question.

Add the 'isolate script' field to your form and set it false. If you're in a scoped app, you'll need to enable script de-isolation following https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0551586 

 

Screenshot 2024-06-26 at 18.48.59.png

I did that already.  That is Tag (1) in my screenshot above.