- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2016 08:32 AM
By default, work_notes has a max length of 4000, but it doesn't work.
I've tried making it work by getting control with g_form.getControl, but that doesn't work either.
var w = g_form.getControl('work_notes');
if (w)
w.setAttribute("maxlength", 1000);
I've tried it with both an onLoad, and onChange. Nothing is able to restrict it.
Initially, I thought it might have been related to the additional container that work_notes and additional_comments are grouped in (starting with Geneva), but I tested it in Fuji as well, and it is a problem across the board.
The reason I need this is because we built an custom table that extends task (hence the work_notes), and they send information from this table to a vendor. The vendor only accepts 1000 characters.
Any suggestions?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2016 08:47 AM
Hi Simon,
You can write a onSubmit Client script for validation. Here you go.
function onSubmit()
{
var wnote = g_form.getValue('work_notes');
if(wnote.length > 1000)
{
alert('YOUR MESSAGE')
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2016 08:39 AM
Hi Simon,
Anything over 1000 is effectively unlimited. I'm still not sure why we have different string values for 1000 and 4000.
If you want to enforce the field length, you would have to write an onChange client script to check it or a custom event handler to check as each character is input. The client script is a supported method using the g_form object. The custom event handler... not sure. I thought I saw something like that in the past, but don't 'see it.
GlideForm (g form) - ServiceNow Wiki
Client Scripts - ServiceNow Wiki
Another option is to turn on the character counter: Enable the text field character counter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2016 08:44 AM
The easiest recommendation off hand is to run an onSubmit script that measures the length of the work_notes, and if it's greater than 1000, fails to submit the page and alerts the user.
The HTML for that field is as such:
<textarea wrap="soft" spellcheck="true" onkeypress="" onkeyup="multiModified(this);fieldTyped(this);" class="form-control" onfocus="this.isFocused=true;" autocomplete="off" data-charlimit="false" rows="220" id="incident.work_notes" data-length="4000" style="direction: ltr; overflow: hidden; word-wrap: break-word; resize: none; height: 64px; background-color: lightgoldenrodyellow;" data-type="glide_journal_input" name="incident.work_notes" onchange="this.isFocused=false;multiModified(this)" onblur="this.isFocused=false;" data-ref="incident.work_notes" onkeydown="multiKeyDown(this);;"></textarea>
Perhaps modifying the "data-length" property would work? (It seemed to work when I ran a script in the console.)
gel('incident.work_notes').setAttribute('data-length', '1000');
You may also want to look at the sys_journal_field table, where the entries are stored on the back end. It looks like my default max length value for "value" is 8000.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2016 08:47 AM
Hi Simon,
You can write a onSubmit Client script for validation. Here you go.
function onSubmit()
{
var wnote = g_form.getValue('work_notes');
if(wnote.length > 1000)
{
alert('YOUR MESSAGE')
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2016 08:58 AM
Try this:
Change the activity-stream-textarea to whatever your element would be.
document.getElementByID("activity-stream-textarea").setAttribute("maxlength", "1000");
Kind regards,
Sourabh
Do not forget mark this answer as correct if you fell so.