Word limit for Multi line text variable in Record Producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 03:27 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 03:37 PM
Hi Sharon,
If you're setting a limit of 1500 words and you are doing the validation on an onChange client script, I think you will have a lot of script executions on the client side.
I would try to change the requirement to focus on the number of characters instead of number of words. That is an OOB feature and you don't need to do nothing to use it.
If the requirement still persists, you can do the validation onSubmit. The downside is that your users might write a huge text and only on submit they will know that they wrote more than expected!
This can be bypassed if you set an infoMessage on that field information that the max word count is 1500.
The validation can consist simply in something like this:
var words = g_form.getValue("your_field").split(" ").length;
if(words > 1500){
//inform user
}
You can simply do a split by the " " (space) character, to catch the different words.
In the end, use your code but change the "split" input.
Try it out and check if that works! And check if you want to use an onChange or an onSubmit Client script.
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 04:24 PM
Hi Sharon,
Following onLoad script will add an error message to multi-line text field if number of characters is more than max length in UI. Additional script is required to make it work on Service Portal.
The sample sets max length to 10 characters.
function onLoad() {
var fieldName = 'multiline_text'; // name of multiline text field
var maxLength = 10; // max length of multiline text field
try {
var control = g_form.getControl(fieldName);
control.onkeyup = function isMaxLength() {
var control = g_form.getControl('multiline_text');
if (control.value.length > maxLength) {
g_form.hideErrorBox(fieldName);
try {
g_form.showFieldMsg(fieldName, 'Please limit number of characters to ' + maxLength + ' characters.', 'error');
} catch (e) {}
control.value = control.value.substring(0, mLength);
} else {
g_form.hideErrorBox(fieldName);
}
};
} catch (e) {
alert(e.message);
}
}
Execution result:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 06:47 PM
Thanks Hitoshi
But it doesn't work for me. I even created a multiline text variable which was exactly same as 'multiline_text', and copy paste your script. Still doesn't work. Is there anything else I need to configure?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 07:06 PM