- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2023 10:34 PM - edited 06-18-2023 10:34 PM
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();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 12:44 AM
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;
}
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2023 10:36 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2023 11:53 PM
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;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 12:41 AM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 12:44 AM
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;
}
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader