- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 03:26 AM
Hello, I would like to show an error when user click submit button and if short_description field is less than 10 characters, I have created a client script, but the error message is showing as single line, I have triedn /n and <br>. Is there any workaround? Can I use this script in the butto as well?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 03:45 AM - edited 08-12-2024 04:55 AM
Hi @Camillo ,
Sadly line breaks (\n or <br>) are not supported via g_form showFieldMsg() method. (At least not currently for others looking at this in the community))
You can however achieve pretty much what you want by tweaking the script slightly as below:
function onSubmit() {
var shortDescription = g_form.getValue('short_description');
if (shortDescription.length < 10) {
g_form.showFieldMsg('short_description', 'The title is too short. Necessary information might be missing. *Please do not submit.', 'error');
g_form.showFieldMsg('short_description', '*Please do not submit.', 'error');
}
return false; // Prevent submission
}
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 03:31 AM
Hi @Camillo
Check this,
g_form.showFieldMsg('short_description', 'The title is too short. Necessary information might be missing.' + \n + 'Please do not submit.', 'error');
A string concatenated with new line, then again concatenated with other string. Else, \n is also taken as a part of string.
If it helps you, marks it has helpful and accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 03:45 AM - edited 08-12-2024 04:55 AM
Hi @Camillo ,
Sadly line breaks (\n or <br>) are not supported via g_form showFieldMsg() method. (At least not currently for others looking at this in the community))
You can however achieve pretty much what you want by tweaking the script slightly as below:
function onSubmit() {
var shortDescription = g_form.getValue('short_description');
if (shortDescription.length < 10) {
g_form.showFieldMsg('short_description', 'The title is too short. Necessary information might be missing. *Please do not submit.', 'error');
g_form.showFieldMsg('short_description', '*Please do not submit.', 'error');
}
return false; // Prevent submission
}
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 04:06 AM
Hi @Camillo
I would suggest to go with the approach to add every message on new line as \n or <br> are not supported in showFieldMsg.
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 04:32 AM
Hi @Camillo
The g_form.showFieldMessage() do not supports line break (\n). Instead of that you can add 2nd or 3rd field message for same field so that it can show message in new line/block.
Refer below post :
https://www.servicenow.com/community/itsm-forum/line-break-in-g-form-showfieldmsg/m-p/501020/page/2
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.