Client script seems to run twice. Wondering why?

artguerra
Kilo Contributor

In our Fuji environment, I have a page within a module that runs two client scripts. Each script runs g_form.addErrorMessage(...) in the OnLoad event to display an message to the user. In one environment this works as expected; the user sees the two error messages at the top of the page above the page controls which appear below them.

However in a separate Fuji environment, the error messages are duplicated. There are two of each displayed making a total of 4 error messages at the top of the page. It seems as of the OnLoad event is running twice.

If the scripts were not in the OnLoad event I would think perhaps they were being called from somewhere I am not aware of. But since they are in the OnLoad event I'm not quite sure where to go from here.

Any suggestions on where to check for these scripts being called, or why an OnLoad script would run twice would be most appreciated. I am fairly new to ServiceNow so apologies if I have neglected to provide any piece of fundamental information.

1 ACCEPTED SOLUTION

Mike Allen
Mega Sage

I would start by turning the one you know about off and see if you still get two messages or no message.   If you get 2, it means you have a duplicate somewhere.   If you get none, it means there is something in your script that is not acting correctly.



Also, please post screenshots of your client script, or a close proximate of it.   This will help us rule that particular piece out.


View solution in original post

5 REPLIES 5

Mike Allen
Mega Sage

I would start by turning the one you know about off and see if you still get two messages or no message.   If you get 2, it means you have a duplicate somewhere.   If you get none, it means there is something in your script that is not acting correctly.



Also, please post screenshots of your client script, or a close proximate of it.   This will help us rule that particular piece out.


Thank you for the response Mike. I will try disabling the script right away to see what happens. Below is a screenshot of the script itself. It's very straight-forward and consists only of the function definition and the single call to addErrorMessage.


ScriptSample.jpg


Hi Arthur,



Kindly check if you have a duplicate script as well which is running on the same time.



Thanks,


Abhijeet


The SN Nerd
Giga Sage
Giga Sage

What happens if you put both error messages into one script include then disable the other?



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022