- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 12:10 PM
Hi All,
I have one Text field in Problem form .
I want to restrict user to enter only 500 characters if its more then it should not allow.
In Max length i have given 500 still its taken more than 500 and its known error in Servicenow
SO i have written on change client script as below
---------------------------------------------------------
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var control = g_form.getControl('u_observation');
if (control.value.length > 500) {
//g_form.hideErrorBox('u_observation');
//g_form.showErrorBox('u_observation', 'You have reached the maximum limit of ' + 500 + ' characters for this field.');
alert('You can not put more than 500 characters to Observation field');
control.value = control.value.substring(0, 500);
} else {
g_form.hideErrorBox('u_observation');
}
}
-------------------------------------
As per onchange once i click outside of field then only alert is popping and characters after 500 getting deleted.
Is there any way i can restrict to enter only?
Regards,
Roopa
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 12:24 PM
This solution still seems to work.
Something like this in an onload script:
function onLoad() {
var control = g_form.getControl('u_observation');
//Set its onkeyup method
control.onkeyup = isMaxLength;
}
function isMaxLength() {
var mLength = 100;
var control = g_form.getControl('u_observation');
if (control.value.length > mLength) {
g_form.hideErrorBox('u_observation');
g_form.showErrorBox('u_observation', 'You have reached the maximum character limit for this field.');
control.value = control.value.substring(0, mLength);
} else {
g_form.hideErrorBox('u_observation');
}
}
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 12:24 PM
This solution still seems to work.
Something like this in an onload script:
function onLoad() {
var control = g_form.getControl('u_observation');
//Set its onkeyup method
control.onkeyup = isMaxLength;
}
function isMaxLength() {
var mLength = 100;
var control = g_form.getControl('u_observation');
if (control.value.length > mLength) {
g_form.hideErrorBox('u_observation');
g_form.showErrorBox('u_observation', 'You have reached the maximum character limit for this field.');
control.value = control.value.substring(0, mLength);
} else {
g_form.hideErrorBox('u_observation');
}
}
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 12:37 PM
Thank u so much it works
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 12:44 PM
the script which i have shown that did not work ?
Note: if you will use getControl() on portal, in future deployment, that will not work.