How to get TYPE of instance via script.

JefDeCoster
Giga Contributor

Hi all,

Using following doesn't work:

var IsProductionInstance = GlideUtil.isProductionInstance();

var IsNonProductionInstance = GlideUtil.isDeveloperInstance();

var IsProductionInstance = gs.getProperty('glide.installation.production');

This will always report true on isProductionInstance() and ('glide.installation.production').

Thus it seems that (even if you are on a non-production instance) these are not properly set.

 

Is there any other means (gliderecord against a table, another property, ...) to easely retrieve the TYPE of an Instance. 

TYPE as shown on Hi Portal when reviewing your instances...

 

In the meantime I'm using a check on property instance_name to see if it is different from the production instance_name.

But this requires OR a new property in which you set th eProduction instance name to verify against.

OR a fixed String variable in the script itself in which you set the Production instance_name to verify against.

 

KR,

Jef

 

 

 

 

 

 

1 ACCEPTED SOLUTION

JefDeCoster
Giga Contributor

What I did: 

1. Created a new Property , String : glide.installation.production_instance_name

2. Gave it the value as found in Property 'instance_name' on Production instance.

3. Created a new Function in one of my Script Includes '':

/* -- */
	/** NEW Author JDC dd 24/09/2019
	//Get flag to check if this is the production instance 
	//  var GUu = new General_Usable_Utils();
	//  var isProductionInstance = GUu.IsProductionInstance(); //returns Boolean 'true' or 'false'
	**/
IsProductionInstance: function(){ //Activate in Script Include
//function IsProductionInstance() { //Comment Out in script include//used in Fix Script to test
	var InstanceName = "";
		InstanceName = (gs.getProperty('instance_name').toString());
	var ProductionInstanceName = "";
		ProductionInstanceName = (gs.getProperty('glide.installation.production_instance_name').toString());
	var ReturnFlag = false;
		ReturnFlag = (InstanceName === ProductionInstanceName);
	return ReturnFlag;
	//} //Comment Out in script include//used in Fix Script to test
	}, //Activate in Script Include
/* -- */

4. Now you can easily use this to get a proper answer to your question, and thus replace the use of GlideUtil.isProductionInstance();

Example:

//Example of script to use in On Before Business Rule on top of sys_email:
var isProductionInstance = false;
    isProductionInstance = new General_Usable_Utils().IsProductionInstance();
var addNonProdNotificationHeader = false;
    addNonProdNotificationHeader = (!isProductionInstance);
var NonProdNotificationHeader = "";
var NotifBody = current.body;
if (addNonProdNotificationHeader) {
    NonProdNotificationHeader = new Email_Utils().GetNonProdNotificationPreHeader();
    current.body = NonProdNotificationHeader + NotifBody;
}

 

Thus indeed I created my own property and created a function to check against instance_name....

 

View solution in original post

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

You could create your own property for your instance stack and set it to true in your prod instance and false in your subprods if it has to be boolean. That being said, in the past I've always just checked the instance_name property as you mentioned in your post.

JefDeCoster
Giga Contributor

What I did: 

1. Created a new Property , String : glide.installation.production_instance_name

2. Gave it the value as found in Property 'instance_name' on Production instance.

3. Created a new Function in one of my Script Includes '':

/* -- */
	/** NEW Author JDC dd 24/09/2019
	//Get flag to check if this is the production instance 
	//  var GUu = new General_Usable_Utils();
	//  var isProductionInstance = GUu.IsProductionInstance(); //returns Boolean 'true' or 'false'
	**/
IsProductionInstance: function(){ //Activate in Script Include
//function IsProductionInstance() { //Comment Out in script include//used in Fix Script to test
	var InstanceName = "";
		InstanceName = (gs.getProperty('instance_name').toString());
	var ProductionInstanceName = "";
		ProductionInstanceName = (gs.getProperty('glide.installation.production_instance_name').toString());
	var ReturnFlag = false;
		ReturnFlag = (InstanceName === ProductionInstanceName);
	return ReturnFlag;
	//} //Comment Out in script include//used in Fix Script to test
	}, //Activate in Script Include
/* -- */

4. Now you can easily use this to get a proper answer to your question, and thus replace the use of GlideUtil.isProductionInstance();

Example:

//Example of script to use in On Before Business Rule on top of sys_email:
var isProductionInstance = false;
    isProductionInstance = new General_Usable_Utils().IsProductionInstance();
var addNonProdNotificationHeader = false;
    addNonProdNotificationHeader = (!isProductionInstance);
var NonProdNotificationHeader = "";
var NotifBody = current.body;
if (addNonProdNotificationHeader) {
    NonProdNotificationHeader = new Email_Utils().GetNonProdNotificationPreHeader();
    current.body = NonProdNotificationHeader + NotifBody;
}

 

Thus indeed I created my own property and created a function to check against instance_name....

 

Dan T_
Tera Guru

Check the system property "sn_appclient.instance_type".  It's a string with "subproduction" or "production".