I have created a field %Complete where it should allow only numbers from 0 to 100
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have created a field %Complete where it should allow only numbers from 0 to 100 what can be the simple and best possible ways to do this ?
Can we do field validation with in dictionry?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
You can use a UI Policy and apply a relative operator.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you can make the field as Type=Integer and then use onChange client script on that field and handle the value check + Business rule
Use onChange client script for Form validation
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
return;
var n = parseInt(newValue, 10);
if (isNaN(n) || n < 0 || n > 100) {
g_form.showFieldMsg('u_percent_complete', 'Enter a value between 0 and 100.', 'error');
g_form.clearValue('u_percent_complete');
}
}
You also need business rule in case somebody updates the field from list
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
if (!gs.nil(current.u_percent_complete)) {
var n = parseInt(current.u_percent_complete, 10);
if (isNaN(n) || n < 0 || n > 100) {
gs.addErrorMessage('% Complete must be between 0 and 100.');
current.setAbortAction(true);
}
}
})(current, previous);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Shaik Najma
Refer : Percent complete field type
Implement an onChange Client script to validate it.
- Table: Select the table of your form.
- Type: onChange
- Field Name: Select your Percent Complete field (e.g., percent_complete)
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { return; } var enteredValue = parseFloat(newValue); if (enteredValue > 100) { g_form.setValue('percent_complete', 100); // Resets to 100 g_form.showFieldMsg('percent_complete', 'Percent complete cannot exceed 100.', 'error', false); } else if (enteredValue < 0) { g_form.setValue('percent_complete', 0); // Resets to 0 g_form.showFieldMsg('percent_complete', 'Percent complete cannot be less than 0.', 'error', false); } }
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Shaik Najma
I used percent complete field type ,it allows only the numbers
and,you use the client script to check the range
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if ( newValue < 0 || newValue >= 100) {
g_form.showFieldMsg('u_complete', 'Please enter a value between 0 and 100', 'error');
g_form.setValue('u_complete', '');
}
}
hope it helps