Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Creating a report that tracks changes in knowledge article content

MatissK
Giga Contributor

Hi,

First time poster, long time lurker, as they say... 

Is there a way to create a report that tracks which articles have not had any changes to content made, when "Valid to" date is updated?

 

My company wants to keep track of which articles are simply updated with a new "Valid to" date but the content is kept unchanged.

Is this possible?

2 REPLIES 2

Kieran Anson
Kilo Patron

A simple option would be to use an empty metric definition, and trigger it via a business rule

 

  1. Create a metric definition. This is effectively a placeholder record for reporting purposes, it won't be triggered by the usual metric processing engine as that only runs on task extended tables by default.

KieranAnson_0-1762180640331.png

 

  1. Create an after BR that'll update the metric. The BR should have a filter condition to only update if the valid to field changes. In the scripted condition you can add the following
!current.text.changes()
(function executeRule(current, previous /*null when async*/) {

	var metric = new global.MetricInstance('definition gliderecord here' , current)

	if(!metric.metricExists()){
		var metricGR = metric.getNewRecord();
		metricGR.setValue('value', 1); //first metric
		metricGR.update();
	} else {
		//get the existing metric and increment 
		var metricUpdateGR = new GlideRecord('metric_instance');
        metricUpdateGR.addQuery("id", current.getUniqueValue());
        metricUpdateGR.addQuery("definition", 'sys_id_of_definition_record');
		metricUpdateGR.setLimit(1);
		metricUpdateGR.query();
		if(metricUpdateGR.next()){
			currentValue = Number(metricUpdateGR.getValue('value'))
			metricUpdateGR.setValue('value' , currentValue ++);
			metricUpdateGR.update();
		}
	}

})(current, previous);

 

Thank you for the suggestion! Just to clarify, the "definition gliderecord here" means the reference to the metric created before, right?

Also, what is a glide record in this context?

var metric = new global.MetricInstance('definition gliderecord here' , current)