Looking to add some helpful functionality to your ServiceNow Ajax scripts? I have just the thing for you!
If you are familiar with writing Ajax Script Includes, you’ll know that those are meant to be used for client side. Well, what if I told you there was a simple way to have those functions callable from server side and client side with inputs?
Here is a code snippet:
In the ‘exampleFunction’, it only handles the input from the sysparm that is sent over when making a GlideAjax call. This input value won’t be found if you are running on Server side.
The revisedExampleFunction has the ability for a standard input to be passed into it. This allows you to run this code snippet on Server Side by passing the input through to the function call. Since the inputValue parameter that comes from function call will start off as null, it works fine on Client, as it will then set it to GlideAjax parameter just like the first function did.