How to popup message or alert on Servicenow portal for Quantity drop-down field ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2020 11:12 AM
Hi All,
I want to popup a message /alert if user is selecting more than 8 quantity in the below drop down field(snap 1).
Do I need to do the coding in HTML template or Client script or Server script ? I have find coding part for this field in HTML template (snap2)
Please let me know how I can popup message and stop user to select more than 8 number /qty ?
Snap1:
Snap2:
Thank you.
Regards,
Virendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2020 11:59 PM
If you try that approach it would be global change I believe since it will for all catalog items.
1) If you want this for all catalog items then you can disable those 2 drop down choices of 9 and 10 for sc_cart_item table
2) if you want for specific catalog item then you can have onSubmit catalog client script to check for quantity
Ensure: Isolate script is set to false; this field is not on form but from list you can set it to false; by default it is true
Sample Script below; it worked for me in native and portal both
Note: this includes using DOM manipulation
function onSubmit() {
//Type appropriate comment here, and begin script below
if(window == null){
var z = this.document.getElementsByClassName("select2-chosen");
if(z[1].innerHTML > 8 ){
alert('Please select value less than 8');
return false;
}
}
else{
var quantity = $j('#quantity').val();
if(quantity > 8){
alert('Please select value less than 8');
return false;
}
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2020 02:02 AM
Hi Ankur,
It helped me lot, but when I applied above code, I am getting error on portal.When I saw it in console. its is related to "innerHTML"
error msg is , "Cannot read property 'innerHTML' of undefined". Also I am new to the portal but I would like to know, how and where we can fins the control name on portal like you mentioned for dropdown "select2-chosen" ?
snap:
Thanks,
Virendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2021 02:52 AM
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so others with similar questions/issues can find your posting quickly.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2020 02:02 AM
Let me know if that answered your question.
If so, please mark appropriate response as correct & helpful so others with similar questions/issues can find your posting quickly.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader