Oder now button hide

NannuSubhani Sh
Tera Contributor

Hi,

 

We have a variable in catalog item  which is look up select box(country) to location table in this we have 3 question choices(1.India,2.China,3.Japan) if user select 1.India  the order now button should be visible for remaining 2 values  we need to hide the order now button on service portal 

 

I have tried the below catalog On change client script it is not working kindly help on this how to achieve

 

alert('test');
var cntr = g_form.getValue('country');

if (cntr == 'India') {
$(sc_order_now_button).show();
$(sc_add_to_cart_button).show();
} else {
$(sc_order_now_button).hide();
$(sc_add_to_cart_button).hide();

 

1 ACCEPTED SOLUTION

@NannuSubhani Sh 

are you sure you are comparing correct value

Since you said it's a lookup select box then it will hold sysId; so you compare the sysId and not the label

var answer = g_form.getValue("country"); // variable type is look up select box of location table
if (answer != 'sysIdOfIndiaRecord') {
	var msg = getMessage("Request cannot be submitted due to the answer of User Details.");
	g_form.addErrorMessage(msg);
	return false;
}
}
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@NannuSubhani Sh 

to show/hide you need to use DOM manipulation which is not recommended.

Alternative Method:

1) use onSubmit and stop form submission and in that script check the choice value

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

I have tried the below script  but it is restricting for all 3 values we need to allow the access for India and restrict remaining values  kindly suggest on this.

 

var answer = g_form.getValue("country"); // variable type is look up select box of location table
if (answer != 'India') {
var msg = getMessage("Request cannot be submitted due to the answer of User Details.");
g_form.addErrorMessage(msg);
return false;
}
}

Community Alums
Not applicable

Hi there,

 

I have tried adding your script above with onSubmit Catalog client script and it works correctly as only allow Order Now/Add to cart for 'India'. 

 

Let's add an 'alert' to the answer to check for the value and also the type (string)

@NannuSubhani Sh 

are you sure you are comparing correct value

Since you said it's a lookup select box then it will hold sysId; so you compare the sysId and not the label

var answer = g_form.getValue("country"); // variable type is look up select box of location table
if (answer != 'sysIdOfIndiaRecord') {
	var msg = getMessage("Request cannot be submitted due to the answer of User Details.");
	g_form.addErrorMessage(msg);
	return false;
}
}
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader