Adding Multiple Lines/Line Breaks to an error in Client Script

Camillo
Tera Contributor

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? 

 

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. \n*Please do not submit.', 'error');
    }
    return false; // Prevent submission
 
 
}
1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

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

View solution in original post

4 REPLIES 4

Najmuddin Mohd
Mega Sage

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.

Robbie
Kilo Patron
Kilo Patron

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

Ayushi12
Mega Sage

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!

Amit Verma
Kilo Patron
Kilo Patron

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.