- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 06:27 AM
I want to make a field mandatory in an UI Page and by using required tag it is not working. Any workaround? maybe some javascript code or any other thing?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 11:39 PM - edited ‎03-18-2025 11:41 PM
1 way is to use client script in UI page
Other way is check how OOB UI pages from ServiceNow is being done, check that code.
refer these link if that helps
creating a mandatory field in ui page?
Make UI Page Text area mandatory
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 06:44 AM
function validateMandatoryField() {
var field = document.getElementById('mandatoryField');
if (!field.value.trim()) {
alert('This field is mandatory. Please fill it out.');
return false; // Prevent form submission
}
return true; // Allow form submission
}
lets try this code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 11:30 PM
I have to write this in client script section of the UI pAge?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 11:33 PM
yes can you please try it on client script section of the UI page.it should work .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 06:45 AM
Hi @SamiranD , you will need validation in client script to see if the field has value or not.
Can you share your HTML and Client Script?
Please refer:
Solved: UI Page, Reference field mandatory not working - ServiceNow Community