Short description minimum 25 characters with no blank spacing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 06:54 AM
Hi All
I have a requirement to restrict the short description variable to have a minimum of 25 characters without considering the white spaces in the statement
for example "this ticket is created for not getting logged into ServiceNow"
Here we have 9 white spaces in the above statements all these spaces should not be considered only the text should be taken into account for counting the minimum characters count is being satisfied or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 07:38 AM - edited 05-16-2024 07:40 AM
Hi @Sanafelix1323,
For the best UX (User eXperience), consider managing this and providing feedback in 2 places/actions. When the Short Description changes, and onSubmit/save of the form.
Alternatively, you can just get away with the onSubmit / save action if required.
See below scripts.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
onChange Script to show user at the time of the change:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.clearMessages();
var countCurrentShortDesc = newValue.trim().length;
if (countCurrentShortDesc < 25) {
g_form.showFieldMsg('short_description', getMessage('Short Description must be a minimum of 25 Characters exclusing spaces'), 'error'); //Best practice leveraging the getMessage method for translation
}
}
onSubmit Script so as to prevent a user from saving/submitting the form when not meeting the condition:
function onSubmit() {
g_form.clearMessages();
var currentShortDescVal = g_form.getValue('short_description');
var countCurrentShortDesc = currentShortDescVal.trim().length;
if (countCurrentShortDesc < 25) {
g_form.showFieldMsg('short_description', getMessage('Short Description must be a minimum of 25 Characters exclusing spaces'), 'error'); //Best practice leveraging the getMessage method for translation
return false;
}
}