- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2022 05:09 AM
Hi everyone,
Is it possible to add the minimum characters required to the catalog field of variable type multi-line text?
Eg: I want a user to at-least write 30 characters before submitting.
Regards,
Priya
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2022 05:57 AM
Use onSubmit()/onChange() catalog client script as per your requirement.
function onSubmit() {
if(g_form.getValue('<multi_line_variable_backend_name>').length < 30){
g_form.showFieldMsg('<multi_line_variable_backend_name>', 'Enter at least 30 characters.', 'error', true);
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2022 05:59 AM
Hi,
Yes you can validate the length of the variable while submitting the form.
1. Create a onSubmit catalog client script on your catalog item.
try below script
you can add alert or infomessage based on your requirement you can add.
function onSubmit() {
var minLength = 30; //Define the length here
var field1 = g_form.getControl('description'); //Replace description with your variable name
if (field1.value.length < minLength) {
// g_form.addInfoMessage('description should not be less than 30 characters');
alert('Description should not be less than 30 characters');
return false;
}
}
Hope you it helps you.
Please Mark ✅ Correct/helpful if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2022 09:22 PM
Hi,
Thank you for the response.
This is working fine when I try it in the ServiceNow catalog.. but in the Service Portal, it's not working, I can submit the form with less than 30 characters also.
Regards,
Priya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 02:59 AM
Hi,
No it will work in portal as well but you need to select UI type as All in Catalog client script.
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2022 09:21 PM
Hi @Priya
If it is resolved please close the thread by Marking as ✅ Correct so that other readers will get benefit if they have similar question. In future they will refer this question will see solution.
Hope you understood.
Happy learning!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2022 09:31 PM
Hi Priya,
Instead of writing a client script you can actually achieve just by using Variable validation regex.
Create a record in question_regex table and call it in variable. See below for your reference:
^(?=.*\d).{30,}$
Variable screenshot:
Output:
Hope it helps.
Thanks,
Murthy
Murthy