Business Rule Script to set Resolved Boolean in KM Article to True

Katie Boal
Tera Contributor

Hi there,

 

I'm looking to set the "resolved" boolean in Knowledge Feedback in KM Articles when retired to true, and add a little note in on the work notes too. I've tried the below script, but I'm worried I'm not getting the right GlideRecord. Wondering if others have any advise on how to fix this?

 

(function executeRule(current, previous /*null when async*/) {


// See STRY0405702- Resolve to set true to any false-resolve-flag feedback relating to the retired article
	
var myQuery1 = "stateNOT IN3^feedback.article.article_id=" + current.article_id;
//gs.log("Query = " + myQuery1, STRY0405702 business rule");
//gs.log("Sys ID of article = " + current.sys_id, STRY0405702 business rule");
var fbtGr = new GlideRecord('kb_knowledge_feedback');
fbtGr.addEncodedQuery(myQuery1);
fbtGr.query();
while (fbtGr.next()) {
//gs.log("Found knowledge feedback " + fbtGr.number, "STRY0405702 business rule");
// Set 'resolved' flag to 'true' and add some work notes to explain why
fbtGr.resolved = true;
fbtGr.work_notes = '***** This knowledge feedback was auto closed by a business rule that runs when the parent article has been retired *****';	
var fbtGr_sys_id = fbtGr.update();
if (fbtGr_sys_id != null) {
  gs.log("Closed knowledge feedback - " + fbtGr.number, "STRY0238699 business rule");
}
}

})(current, previous);

 

1 ACCEPTED SOLUTION

Got it. Your query looked like it was based on kb_feedback_task though. You can make these changes in your original code then:

  • The table you want to query is 'kb_feedback'
  • There is no state column on the feedback tale, so your query will just be like 

 

"article.article_id=" + current.article_id;​

 

View solution in original post

5 REPLIES 5

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

I think you want your GlideRecord query to run on the kb_feedback_task table, no? That has the columns you are using in your encoded query.

However, it does not have a 'resolved' column (out of the box), only a 'resolution_code' column, which is a string field. Perhaps you could set that instead of adding work notes, and just set active to false?

 

Based on your shared code it would be something like this:

 

(function executeRule(current, previous /*null when async*/) {


// See STRY0405702- Resolve to set true to any false-resolve-flag feedback relating to the retired article

var resolutionMessage = '***** This knowledge feedback was auto closed by a business rule that runs when the parent article has been retired *****';	
var myQuery1 = "stateNOT IN3^feedback.article.article_id=" + current.article_id;
//gs.log("Query = " + myQuery1, STRY0405702 business rule");
//gs.log("Sys ID of article = " + current.sys_id, STRY0405702 business rule");
var fbtGr = new GlideRecord('kb_feedback_task');
fbtGr.addEncodedQuery(myQuery1);
fbtGr.query();
while (fbtGr.next()) {
//gs.log("Found knowledge feedback " + fbtGr.number, "STRY0405702 business rule");
// Set 'active' flag to 'false' and add resolution code to explain why
fbtGr.setValue('resolution_code',resolutionMessage);
fbtGr.setValue('active',false);	
var fbtGr_sys_id = fbtGr.update();
if (fbtGr_sys_id != null) {
  gs.log("Closed knowledge feedback - " + fbtGr.number, "STRY0238699 business rule");
}
}

})(current, previous);

 

And if you don't need the sys_id of the feedback task for anything, then using the updateMultiple() method is more efficient, e.g.:

 

(function executeRule(current, previous /*null when async*/) {


// See STRY0405702- Resolve to set true to any false-resolve-flag feedback relating to the retired article

var resolutionMessage = '***** This knowledge feedback was auto closed by a business rule that runs when the parent article has been retired *****';	
var myQuery1 = "stateNOT IN3^feedback.article.article_id=" + current.article_id;
//gs.log("Query = " + myQuery1, STRY0405702 business rule");
//gs.log("Sys ID of article = " + current.sys_id, STRY0405702 business rule");
var fbtGr = new GlideRecord('kb_feedback_task');
fbtGr.addEncodedQuery(myQuery1);

// Set 'active' flag to 'false' and add resolution code to explain why for each record that matches the query
fbtGr.setValue('resolution_code',resolutionMessage);
fbtGr.setValue('active',false);
fbtGr.updateMultiple();

})(current, previous);

Hi Laszlo,

 

I probably didn't explain to well. I'm wanting to set the resolved boolean for the knowledge feedback tab next to the feedback tasks. 

 

knowledgeci.PNG

 

 

Got it. Your query looked like it was based on kb_feedback_task though. You can make these changes in your original code then:

  • The table you want to query is 'kb_feedback'
  • There is no state column on the feedback tale, so your query will just be like 

 

"article.article_id=" + current.article_id;​