Multiple Error Message for Mandatory field

Mahendra RC
Mega Sage

Hi All,

I have a mandatory field on my form and when I try to create/update a record without filling the data for Mandatory field I am getting error message, which is good. But the issue over here is that the error message is displayed on the screen Multiple times if I click on submit/update button multiple time without filling the data for Mandatory field as shown in below screenshot:

find_real_file.png

I have clicked twice on 'update' button without filling the mandatory field and hence the error is displayed twice. I want this error message to be displayed only once even if i click on update button multiple times. Can anyone please tell me how can I achieve this OR else can anyone help me to know where can I find the code that is displaying this error message(this will also be helpful).

Thanks & regards,

Mahendra Choudhary

1 ACCEPTED SOLUTION

Mahendra RC
Mega Sage

Hi All,

Thanks for you reply, the response from Nikhil was helpful, but still I wasn't able to achieve what I was looking for. Thanks for the link it didn't solved my issue, but gave me a hint. Below is my solution, by which I was able to achieve this:

There is much to explain about this issue, but could not write every thing over here.

field Name : Title (this was the field for which I was getting this issue. This field is mandatory in Dictionary)

In 'Save' button UI Action:

I have made the title field non-mandatory only if it is empty as follow:

if(!g_form.getValue('u_title'))

  g_form.setMandatory('u_title', false);

 

in onSubmit Client script :

I have made the title field mandatory as follow: (if you don't do this then title field will be shown as non-mandatory)

  g_form.setMandatory('title', true);

 

So now I am able to get my customized error message below the field by using 'g_form.showFieldMsg' instead of the ServiceNow default for field that is mandatory in dictionary. But now I was getting the message multiple times below title field if I click on submit button on form without filling the data, so below is the solution to fix this issue as well:

in onSubmit Client script:

I have hidden the previous message shown below the field and show new message as follow:

   if(!g_form.getValue('title')) {
     g_form.hideFieldMsg("title");
     g_form.showFieldMsg("title", "Please enter the title for Alert", "error");

}

 

This resolved my issue. posting this solution here so that it may be helpful to someone else.

 

Thanks,

Mahendra

View solution in original post

12 REPLIES 12

Upender Kumar
Mega Sage

Hi,

Have you applied this through your own client script validation.

 

Thanks

Mahendra RC
Mega Sage

Hi Upender,

No, this is getting display somewhere from Servicenow inbuild scripts, tried to find the script for this. but I was not able to find the script which is displaying this message.

Thanks

Mohammed_Iqbal
Tera Guru
Hello mahi9315,
 
This is not a service now issue check your script once may be it create loop.
 
please show me your script.
 
Thanks,
Mohammed Iqbal

 

Hi,

I have checked in developer instance. Whenever you press button message count increase.

 

Thanks