Name

global.HorizontalResultHandlerGetName

Description

get the relevant host name to populate the device history for HD The convension to return the name should be IP_something , meaning the prefix should be the IP so when we open the debugger, and we have valid IP we will open the correct debugger window.

Script

var HorizontalResultHandlerGetName = Class.create();
HorizontalResultHandlerGetName.prototype = {
   initialize: function(sys_id) {
      this.sys_id = sys_id;
  	this.ACTIVE = 1; 
  },

  getName: function() {
     
  	var host;
  	var gr = new GlideRecord('cmdb_ci');
  	gr.get(this.sys_id);
  	if (gr.isValid()) {
  		
  		//special case for Switch Stack so we open the device history
  		//for the master
  		var className = gr.getValue('sys_class_name');
  		if (className == 'cmdb_ci_ip_switch') {
  			host = this.getIPSwitchName();
  		} else if (className == 'cmdb_ci_cloud_service_account') {
  			var svcAccountGr = new GlideRecord(className);
  			svcAccountGr.get(this.sys_id);
  			host = svcAccountGr.getValue('name') + '_' + svcAccountGr.getValue('account_id');
  		}
  		else {
  			host = this.getHostNameOrIP(gr);
  		}
  	}
  	        
      return host;
  },
  
  getIPSwitchName : function() {
  	var host ='';
  	var switchGr = new GlideRecord('cmdb_ci_ip_switch');
  	switchGr.get(this.sys_id);
  	var stack = switchGr.getValue('stack');
  	if (stack == this.ACTIVE) {
  		host = switchGr.getValue('ip_address') + '_' + switchGr.getValue('name') + '_' + switchGr.getValue('stack_mode');
  	}
  	else {
  		host = this.getHostNameOrIP(switchGr);
  	}
  	return host;
  },
  
  getHostNameOrIP : function(gr) {
  	var host = gr.getValue('ip_address');
  	if (JSUtil.nil(host)) {
  		host = gr.getValue('name');
  	}
  	
  	return host;
  },

  type: 'HorizontalResultHandlerGetName'
};

Sys ID

998fd3609fb313004deb91aec32e708d

Offical Documentation

Official Docs: