- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi All,
I want to make character length of a string field of at least 40 character . Is there any way configure it without scripting or we have to approach through script ?
Thank You
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
on string field in dictionary you can use max_length to allow max characters
but nothing OOTB is present for minimum length
you will require onChange client script for this.
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
3 weeks ago
Hi @1_DipikaD,
You can set the maximum character length in the Dictionary for that field. However, if you also want to ensure the field contains at least 40 characters, you’ll need to add an onChange client script on field to enforce that.
----------------------------------------------------------------------------------------------------------------------------------------------
Please mark my response helpful and accept as solution
Thanks & Regards
Mayank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday - last edited Friday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
user enters some text, your script validates the length
if length is less than 60 you show error box and clear the field
why are you setting the value again in that field? let user type in fresh
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var minLength = 60;
if (newValue.length < minLength) {
g_form.showErrorBox('u_build_state_justification', 'The field must contain at least ' + minLength + ' characters.');
} else {
g_form.hideErrorBox('u_build_state_justification');
}
//Type appropriate comment here, and begin script below
}
💡 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 || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday - last edited Friday
Can we make the same thing on 'onsubmit' client script ? With changing of oldValue ?
I mean while this error appears it should not allow the form to be submitted .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
yes you can throw error near field using onSubmit client script as well
like this
when error box is shown near field then form cannot be submitted and no need to use return false
function onSubmit() {
var val = g_form.getValue('u_build_state_justification');
var minLength = 60;
if (val.length < minLength) {
g_form.showErrorBox('u_build_state_justification', 'The field must contain at least ' + minLength + ' characters.');
} else {
g_form.hideErrorBox('u_build_state_justification');
}
//Type appropriate comment here, and begin script below
}
💡 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 || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday - last edited yesterday
Is it ok if I try the below script ? But the new value is getting saved even it is less than 60 character , ideally it should not allow to submit ? I just want to through this error while the field value changes and should not allow to submit the form if condition satisfies .