Friday, June 22, 2018

Get Instance name from script in ServiceNow

Get the instance name from BusinessRule  in ServiceNow to avoid Hardcoding.

Create a Global variable  and assign the instance to it and here is the code below:

//Getting the instance name -- Check sys_properties table and find the value of instance_name

var instancename = gs.getProperty('instance_name');
gs.log('instance name is -->' +instancename);

var env = ' ';

//check if instance name contains dev or uat or anything
if(instancename.indexOf('dev') > -1)
{
env = "DEV";
gs.log('it is instance-->' +env);
}else if(instancename.indexOf('uat') > -1 )
{
env = "UAT";
gs.log('it is instance-->' +env);
}else
{
env = "PROD";
gs.log('it is instance-->' +env);
}

var midserver = 'MIDServer_'+env+'15_1';

var mid = new GlideRecord('ecc_agent');
mid.addQuery('name',midserver);
mid.query();
if(mid.next())
{
}

No comments:

Post a Comment

Discovery troubleshooting | Error messages

  Discovery troubleshooting | Error messages - Support and Troubleshooting (servicenow.com) Description Learn how to resolve common Discover...