Multiline Variable in catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 05:51 AM
Hi Team
How to restrict the users to add more than 5 points in multi line field in catalog item .ex question called "Description of the application" it include only 5 points line
1.
2.
3.
4.
5.
help me to achieve this requirement .attached an attachment where i can't able to add more than 5 .
Thanks in advance !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 10:30 AM
Hello @Snehal
You need onChange Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Split the input by newlines and count lines
var linesCount = newValue.split('\n');
if (linesCount.length > 5) {
// Trim to first 5 lines
var trimmedLinesCount = linesCount.slice(0, 5).join('\n');
g_form.setValue('description_of_the_application', trimmedLinesCount);
alert('You can only enter up to 5 points.');
}
}
NOTE: The catch is: user may end up typing let's say 10 lines or points and he/she will not be prompted with anything however the moment click to select any other field to populate value then only the alert will pop-up.
Validation Result:
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 08:49 PM
you can use onChange catalog client script for this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
g_form.hideFieldMsg('description_of_the_application'); // your variable name
var lines = newValue.split('\n');
if (lines.length > 5) {
g_form.showFieldMsg('description_of_the_application', 'You can only add up to 5 points.', 'error'); // your variable name
g_form.clearValue('description_of_the_application'); // your variable name
}
}
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