Name

sn_grc.BasicIndicatorStrategyBase

Description

Basic strategy for the indicators

Script

var BasicIndicatorStrategyBase = Class.create();

BasicIndicatorStrategyBase.prototype = Object.extendsObject(IndicatorStrategy, {
  
  run: function() {
  	var resultId = "";
  	// Retrieve the table of the profile documentId
  	var item = this.indicatorRecord.item;
  	
  	if (item != null) {
  		var profile = item.profile;
  		
  		if (profile != null) {
  			var count = new GlideAggregate(this.indicatorRecord.reference_table);
  			var criteria = this.indicatorRecord.getValue("criteria");
  			if (criteria != null && criteria != '')
  				count.addEncodedQuery(criteria);
  			if (this.indicatorRecord.use_reference_field)
  				count.addQuery(this.indicatorRecord.getValue("reference_field"), profile.applies_to);
  			count.addAggregate('COUNT');
  			count.query();
  			count.next();
  			
  			var value = "";
  			var totalCount = count.getAggregate('COUNT');
  			var threshold = totalCount;
  			var target = 0;
  			
  			if (this.indicatorRecord.target_type == "percentage" && !this.indicatorRecord.target.nil()) {
  				count = new GlideAggregate(this.indicatorRecord.reference_table);
  				criteria = this.indicatorRecord.getValue("criteria");
  				if (criteria != null && criteria != '')
  					count.addEncodedQuery(criteria);
  				var additionalCriteria = this.indicatorRecord.getValue("additional_criteria");
  				if (additionalCriteria != null && additionalCriteria != '')
  					count.addEncodedQuery(additionalCriteria);
  				if (this.indicatorRecord.use_reference_field)
  					count.addQuery(this.indicatorRecord.getValue("reference_field"), profile.applies_to);
  				count.addAggregate('COUNT');
  				count.query();
  				count.next();
  				
  				if (totalCount > 0)
  					threshold = Math.round((count.getAggregate('COUNT') / totalCount) * 100.0);
  				
  				target = this.indicatorRecord.target;
  				value = threshold + '';
  			}
  			
  			if (this.indicatorRecord.target_type == "count" && !this.indicatorRecord.target.nil()) {
  				target = this.indicatorRecord.target;
  				value = totalCount + '';
  			}
  			
  			var indicatorTarget = this.indicatorRecord.target + '';
  			var indicatorTargetType = this.indicatorRecord.target_type;
  			
  			if ((threshold > target) || (!gs.nil(indicatorTargetType) && threshold == target)) {
  				if (this.indicatorRecord.passed == "passed")
  					resultId = this.addResult(true, "", value, "", indicatorTargetType, indicatorTarget);
  				else
  					resultId = this.addResult(false, "", value, "", indicatorTargetType, indicatorTarget);
  			} else {
  				if (this.indicatorRecord.passed == "passed")
  					resultId = this.addResult(false, "", value, "", indicatorTargetType, indicatorTarget);
  				else
  					resultId = this.addResult(true, "", value, "", indicatorTargetType, indicatorTarget);
  			}
  			
  			if (resultId != '')
  				this.collectSupportingData(resultId);
  		} else {
  			var pt = new sn_grc.GRCUtils().getMessage("profile_lower");
  			gs.addErrorMessage(gs.getMessage("The {0} has no item associated",pt));		
  		}	
  	} else
  		gs.addErrorMessage(gs.getMessage("The indicator has no item associated"));
  	return resultId;
  },

  type: 'BasicIndicatorStrategyBase'
});

Sys ID

d87ebdc25332020042579c25911c080d

Offical Documentation

Official Docs: