Have you ever had a script that needed to work different in each environment? Say for instance you have a REST call that should be connecting to a Dev API in Dev and a Prod API in Production?
I have the solution for you.
The solution isn’t all that complicated. Take a look.
var instance = gs.getProperty(‘instance_name’, ”);
var apiUrl = ‘.service-now.com’;
var environmentallyAwareProperty = gs.getProperty(instance + apiUrl);
The final value you get here would look like this (as an example):
dev0001.service-now.com
The instance variable uses the ‘instance_name’ property that is supposed to exist in your environment. If it doesn’t, I advise setting it up.
ServiceNow urls have 2 parts. It has the service-now.com as well as a instance_name. It should look like this in your url: instance_name.service-now.com
Instance_name will be different based on your environment(s).
To setup the instance_name property, you would just want to have it be the value of your current instance. This means in each environment you will only have this property once and it should be that environment’s instance_name.
Once you have the instance_name property working, you will need to set up a few more property for the environment aware script.
You will need to set up a property for each ServiceNow instance you have.
Example:
dev.service-now.com
test.service-now.com
prod.service-now.com
This allows these properties to be called based on your instance_name, and allow you to do functionality for each one. In our example I show dev.service-now.com. This makes sense if you are connecting to another servicenow instance and you only want it to do so based upon your own instance.
This property can be set up for other situations, such as getting a specific api key per environment (dev.google.api_key as another example). There are no limits to this approach.