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,

I had a call with SeriveNow HI member regarding some issue in Kingston. I raised the same issue and shared my screen. Then i got the reply that its feature of new enhancement. In early release message was disappeared after some time. Now it will be there until you will not close it by clicking X button.

 

Thanks

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

tim2222
Tera Expert

I can confirm this is still the behaviour in the London release.

The new implementation doesn't work well with checkboxes. For us, the error pops above the form layout (see below), so this error can be invisible to the user if they're scrolled down. As the form also doesn't scroll to the checkbox it appears as if nothing happens when the user clicked the Submit.

(Before, alerts would always appear and have to be dismissed in order to proceed, regardless of where the user is scrolled to.)

find_real_file.png