How to identify which instance you are on

Johannes Mweli
Giga Guru

Hi ServiceNow Community Developers,

Do you know if there is a way to identify through a script which instance you are on? For instance I have 3 properties that I have defined for dev, test and prod. Right now in dev I have a hard-coded dev property in my script. When I move my code to test I need to remember to change the code to reference the test property and the same thing when I move to prod, I will also need to remember to change the property. Is there a way to dynamically figure out which property to use based on the instance I am on? For instance how can I say - if dev then use this property, if test then use this one and if prod then use that one, something like that. Please advise.

Thanks,

Johannes

 

1 ACCEPTED SOLUTION

Elijah Aromola
Mega Sage

You could do:

var instanceName = gs.getProperty('instance_name');

If your instance was dev44665.service-now.com it would return just dev44665. You can also use: 

var instanceURL = gs.getProperty('glide.servlet.uri');

This would return your entire instance base URL.

Please mark my answer as helpful/correct if it resolved your issue!

View solution in original post

3 REPLIES 3

Elijah Aromola
Mega Sage

You could do:

var instanceName = gs.getProperty('instance_name');

If your instance was dev44665.service-now.com it would return just dev44665. You can also use: 

var instanceURL = gs.getProperty('glide.servlet.uri');

This would return your entire instance base URL.

Please mark my answer as helpful/correct if it resolved your issue!

Johannes Mweli
Giga Guru

Wow, that does work indeed. Thanks a lot Elijah!

Jim Coyne
Kilo Patron

The other way of doing it is you have 1 System Property and you use a Clone Data Preserver to preserve the values in the sub-prod instances.  That way you just always use the same property, it would just contain different values in the different instances.

That way you don't have to worry about or check to see what instance you are in.