Name

sn_cmp.RefQualsCMP

Description

No description available

Script

var RefQualsCMP = Class.create();
RefQualsCMP.prototype = {
  initialize: function() {
  },

  getColumnsForTable : function (tableName) {
  	gs.info('current table: ' + current.getTableName() + ', ref table: '  + tableName);

  	var excludedTypes = ["collection"];
  	var systemColumns = ["sys_id","sys_created_on","sys_created_by","sys_updated_on","sys_updated_by"];

  	//var dbom = GlideDBObjectManager.get();
  	//var includeTables = '' + dbom.getTables(tableName);
  	var includeTables = '' + new GlideTableHierarchy(tableName).getTables();
  	var refQual = 'nameIN' + includeTables;
  	// remove the leading and trailing square braces
  	// var refQual = 'nameIN' + includeTables.substring(1, includeTables.length-1);
  	refQual += '^elementNOT IN' + systemColumns.join();
  	refQual += '^internal_typeNOT IN' + excludedTypes.join();
  	return  refQual;
  },
  
  getLogicalDatacenters : function( cloudAccountId){
  	if( !cloudAccountId){
  		cloudAccountId = this.getParameter("cloudAccountId");
  	}
  	var gr = new GlideRecord('sn_cmp_ca_assc_datacenter');
  	gr.addQuery('cloud_account', cloudAccountId);
  	gr.query();
  	var ldc_ids = "";
  	var i = 0;
  	while (gr.next()){
  		if( i > 0){
  			ldc_ids += ",";
  		}
  		i++;
  		ldc_ids += gr.getValue('ldc_id');

  	}
  	var outputStr = "sys_idIN"  + ldc_ids;
  	return outputStr;

  },
  
  getImagesForLDC : function( ldcId, type){
  	var ciObj = "cmdb_ci_os_template,cmdb_ci_vmware_template";// need this for vSphere
  	if( !ldcId){
  		ldcId = this.getParameter("ldcId");
  	}
  	if( !type){
  		type = this.getParameter("type");
  	}
  	if( !type){
  		type = "os";
  	}
  	if( type == "compute"){
  		ciObj = "cmdb_ci_compute_template";
  	} else if (type == "volume"){
  	    ciObj = "cmdb_ci_volume_template";
  	}else if( type == "securitygrp"){
  		ciObj =  "cmdb_ci_security_grp_template";
  	}

  	var expressionResolver = new sn_cmp_api.ExpressionResolverUtilScript();
  	var templates = expressionResolver.getMetadataRelations(ldcId, "Hosts", ciObj, "flat", 1);
  	var templatesObj = global.JSON.parse( templates);
  	var sysIds = [];
  	templatesObj.forEach(function(elem){
  		sysIds.push(elem.value);
  	});


  	var table = ciObj;
  	var queryCondition = "";
  	if(type == 'os')
  	{
  		table = 'cmdb_ci_os_template';
  		queryCondition = "os_sys_class_name=cmdb_ci_os_template^ORos_sys_class_name=cmdb_ci_vmware_template";

  	}

  	var exclGr = new GlideRecord("sn_cmp_"+table+"_location");
  	exclGr.addNullQuery("relci_child");
  	if(!gs.nil(queryCondition))
  		exclGr.addEncodedQuery(queryCondition);
  	exclGr.query();
  	var col = type+"_sys_id";
  	while(exclGr.next())
  		sysIds.push(exclGr.getValue(col));

  	var outputStr = "sys_idIN"  + sysIds.join(',');
  	return outputStr;
  },

  getIntegrationUser : function() {
  	var validUserIds = [];
  	var user = new GlideRecord('sys_user_has_role');
  	user.addActiveQuery();
  	user.addQuery("role.name", "sn_cmp.cloud_event_integration");
  	user.query();

  	while(user.next()) {
  		validUserIds.push(user.getValue("user"));
  	}

  	return 'sys_idIN' + validUserIds.toString();
  },

  getAzureServiceAccount : function() {
  	var validAccountIds = [];
  	var account = new GlideRecord('cmdb_ci_cloud_service_account');
  	account.addQuery("discovery_credentials.type", "azure");
  	account.addQuery("datacenter_type","cmdb_ci_azure_datacenter");
  	account.query();

  	while(account.next()) {
  		validAccountIds.push(account.getUniqueValue());
  	}

  	return 'sys_idIN' + validAccountIds.toString();
  },

    getResourceGroupForSA : function(accountSysId) {
    var validRGIds = [];
    // Find all LDCs for the account
    var ldcList = new sn_cmp_api.DiscoveryServiceScript().getLdcIds(accountSysId);

    //Query relationship table for any RG that exists in any of the LDCs found above
    var relGr = new GlideRecord('cmdb_rel_ci');
    relGr.addQuery('type.name', "Contains::Contained by");
    relGr.addQuery('child.sys_class_name', 'cmdb_ci_resource_group');
    relGr.addQuery('parent', 'IN', ldcList.join(','));
    relGr.query();
    while(relGr.next()) {
      validRGIds.push(relGr.getValue('child'));
    }

    return 'sys_idIN' + validRGIds.toString();
},
  getBasicCredential : function() {
  	var validCredentialTypes = [];
  	validCredentialTypes.push('basic_auth');
  	gs.info( 'RefQualsCMP = '  + validCredentialTypes.toString() );
  	return 'typeIN' + validCredentialTypes.toString();
  },

  getFiltersForPool : function(poolId) {
      return 'resource_poolIN' + poolId;
  },

  getVariablesForCatalog : function(catalogId) {
  	var validVariableIds = [];
  	var variableGr = new GlideRecord("sn_cmp_variable");
  	if(this.isResourceCatalog(catalogId))
  		variableGr.addQuery("cat_item", catalogId);
  	else {
  		var setjoin = variableGr.addJoinQuery("io_set_item", "variable_set", "variable_set");
  		setjoin.addCondition("sc_cat_item", catalogId);
  	}
  	variableGr.query();
  	while (variableGr.next()) {
  		validVariableIds.push(variableGr.getUniqueValue());
  	}
  	return 'sys_idIN' + validVariableIds.toString();
  },

  getVariablesForAction : function(catalogId, datasourceId, actionType) {
  	var validVariableIds = [];
  	var variableGr = new GlideRecord("sn_cmp_variable");
  	if(this.isResourceCatalog(catalogId))
  		variableGr.addQuery("cat_item", catalogId);
  	else {
  		var setjoin = variableGr.addJoinQuery("io_set_item", "variable_set", "variable_set");
  		setjoin.addCondition("sc_cat_item", catalogId);
  	}

  	if (datasourceId == "5" && actionType == "1")
  		variableGr.addQuery("type", "18");


  	variableGr.query();
  	while (variableGr.next()) {
  		validVariableIds.push(variableGr.getUniqueValue());
  	}
  	return 'sys_idIN' + validVariableIds.toString();
  },


  isResourceCatalog : function(catalogId) {
  	var catalogGr = new GlideRecord("sn_cmp_rsrc_opr_cat_item");
  	return catalogGr.get(catalogId);
  },

  getInterfaceOperations : function(interfaceId) {
  	return 'interface=' + interfaceId;
  },

  getCAPIInterfaces : function(productId) {
  	var getCategoryId = '';
  	var grCapiProduct = new GlideRecord('sn_capi_product');
  	if(grCapiProduct.get(productId)) {
  		getCategoryId = grCapiProduct.getValue('category');
  	}
  	return 'category=' + getCategoryId;
  },


  getInterfaceMethods : function(capiInterfaceId){
  	return 'cloud_api_interface=' + capiInterfaceId;
  },
  
  getConfigInstallables :  function (templateId) {
  	var sysIds = [];
  	var catItemGR = new GlideRecord("sn_cmp_bp_cat_item");
  	catItemGR.query("template_id", templateId);
  	if (catItemGR.next()) {
  		
  		var configProviderId = catItemGR.getValue('config_provider');
  		
  		if (gs.nil(configProviderId)) {
  			var configProviderGR = this.getConfigProviderByName(catItemGR.getValue('config_provider_name'));
  			configProviderId = configProviderGR.getUniqueValue();
  		}
  		var expressionResolver = new sn_cmp_api.ExpressionResolverUtilScript();
  		var templates = expressionResolver.getMetadataRelations(configProviderId, "Hosts", "sn_cmp_cfg_installable", "flat", 1);
  		var templatesObj = global.JSON.parse( templates);
  		templatesObj.forEach(function(elem){
  			sysIds.push(elem.value);
  		});	
  	}
  	
  	var outputStr = "sys_idIN"  + sysIds.join(',');
  	return outputStr;
  },

  getConfigProviderTypes : function () {
  	var sysIds = ['8c50f6020bd50300a682aac125673a2e', '5b8de9a90b8503003246ad4363673a6a'];
  	return "sys_id NOT IN " + sysIds.join(',');
  },
  
  getConfigProviderByName : function (name) {
  	var gr = new GlideRecord('cmdb_ci_workload_config_provider');
  	if (gr.get(name))
  		return gr;
  },
  
  getProviderBasedOnType : function (providerTypeId) {
  	return "provider=" + providerTypeId;
  },

  getConfigProviderName : function (current) {
  	if (gs.nil(current.getDisplayValue('config_provider')))
  		return current.getValue('config_provider_name');
  	else
  		return current.getDisplayValue('config_provider');
  },

  getConfigInstallableName : function (current) {
  	if (gs.nil(current.getDisplayValue('config_installable')))
  		return current.getDisplayValue('config_installable_name');
  	else
  		return current.getDisplayValue('config_installable');
  },

  type: 'RefQualsCMP'
};

Sys ID

78c807049f93220048111f80a57fcf70

Offical Documentation

Official Docs: