- 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 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-19-2025 03:23 AM
I have implemented the above logic. with the below html.
Please advise
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 03:53 AM
both the links I shared has working approach
which one did you try and what's not working?
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-19-2025 04:02 AM
the 1st link worked for me, response from Rahul
HTML:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<style>
label.required::before {
content: '*';
margin-right: 4px;
color: red;
}
label.notrequired::before {
content: '*';
margin-right: 4px;
color: grey;
}
</style>
<label for="input1" id="inputLabel" >Name</label>
<input type="text" ng-model="name" onchange="checkMandatory()" id="demo" />
</j:jelly>
Client Script:
document.getElementById('inputLabel').setAttribute("class", "required");
function checkMandatory(){
if(document.getElementById('demo')!="")
document.getElementById('inputLabel').setAttribute("class", "notrequired");
}
Output
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-19-2025 04:42 AM
Thank you for marking my response as helpful.
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