Script to limit max size of string field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 07:54 AM
Hi,
I have many string fields set to 400 characters. This allows the boxes to be the right size. However I need to stop users putting in too much data. How best to do this with a script?
I tried an On Change Client script, but it didn't work:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
{
return;
}
if(newValue.length>4000)
{
g_form.showErrorBox("your_field","You cannot enter more than 4000 characters",true);
}
}
Can anyone suggest the best way to achieve this?
Thanks Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 07:58 AM
Check this link, this is probably the solution you want. OOB and no code solution
Enable the text field character counter
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 08:56 AM
Thanks that's good to know. Typically it doesn't work in SP though, so that isn't going to work for this case unfortunatley, as far as I can see.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 08:01 AM
Hi,
So the maximum length should be 4000.
Did you try to give alert in the client script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 08:56 AM
I tried but failed, I am using it in SP if that makes a difference?