Map Knowledge Article to KFT from Workflow Editor

TREE_
Tera Contributor

So I'm creating a custom workflow for the Knowledge Base approvals and retires. I've just copied the standard 'Knowledge - Approval Publish' and 'Knowledge - Approval Retire' and then added a script that will generate a Knowledge Feedback Task (KFT) and load it with relevant details regarding user who submitted the publish / retire and hopefully the number of the article. 

 

I have installed the Knowledge Management Advanced plugin to enable version control for Knowledge Base content. 

 

The purpose of this is to create an actionable ticket whenever a publish / retire approval is needed to help track the work that goes into reviewing Knowledge Base contributions. 

 

TL;DR

The problem lies in trying to map the Knowledge Article number that the publish / retire was submitted from to the generated KFT. I'm able to create the record and fill out the fields in the code snippet minus the "feedback.article" field that seems to relate to the KFT record. 

 

This seems to be the cause of a weird way the field squishes the 'number' and 'version' from the kb_knowledge table into the 'feedback.article' field from the kb_feedback_task table. Anyone know a viable solution to map the knowledge article number & version to my generate KFT? 

var kft = new GlideRecord('kb_feedback_task');
kft.initialize();
kft.opened_by = current.user;
kft.feedback.article = current.sys_id; // WHAT DO WE DO HERE???
kft.feedback_task_type = '5';
kft.short_description = "Knowledge - Approve Article";
kft.description = "An article has been submitted to be published and needs to be reviewed and/or approved.";
kft.insert();
1 ACCEPTED SOLUTION

TREE_
Tera Contributor

So I figured this out. The workflow on this isn't immediately obvious, but I think the intended way to produce kb_feedback_task records in ServiceNow is to via a kb_feedback record. 

 

If you have yet to, you will need to enable the, "Create actionable feedback task when an article is flagged," property found in Knowledge Properties (Knowledge -> Administration -> Properties). This enables the use of the OOB 'Knowledge Feedback Task Creation' business rule that will become a dependency of this workflow. 

 

To enable the use of approvals - also necessary for the workflow solution I developed - you will need to set the publish and retire workflows to 'Knowledge - Approval Publish' and 'Knowledge - Approval Retire' respectively. You can manage your knowledge bases from: Knowledge -> Administration -> Knowledge Bases.

 

I then opted to create two new advanced business rules for when an article to submitted for Publishing and when its submitting for Retiring. When you press Publish or Retire on a checked out article, it puts the article in the states, 'Review' and 'Pending Retirement' respectively. Hence, I opted to create a business rule that will trigger when our Knowledge Article's state changes to either 'Review' or 'Pending Retirement.' 

 

For the purposes of my kb_feedback_task record tracking, I created a new choice option for the 'Feedback Task Type' (feedback_task_type) field called, "Knowledge Submissions." This choice option has the value '7.'

 

I've attached screenshots of the business rule setup for the Publishing business rule. The retirement business rule is basically the same but modifying the respective state conditions, and then changing the data you want placed into your KFT. No configuration is needed under the 'Actions' tab as we are not changing any states from the kb_knowledge table. 

br1.png

br2.png

 

The script for the advanced business rule script is as follows: 

(function executeRule(current, previous /*null when async*/) {
	// This section generates a kb_feedback record which will then be handled by the
	// Knowledge Feedback Task Creation business rule to create the kb_feedback_task record.
	var kft = new GlideRecord('kb_feedback');
	kft.initialize();
	kft.user = gs.getUserID();
	kft.article = current.sys_id;
	kft.reason = 'Article Published';	// Custom Comment
	kft.comments = gs.getMessage("{0} has been submitted for publishing and needs to be reviewed then approved/rejected.",current.number);
	kft.insert();

	// Because I wanted to customize the kb_feedback_task record after it's insertion, we run a query
	// for the newly generated task and if it exists then we update it's feedback_task_type field.
	// For this I created a custom feedback_task_type value named, "Knowledge Submissions."
	// If you leave this section out, your kb_feedback_task field will default to "User Feedback."
	var kft_update = new GlideRecord('kb_feedback_task');
	kft_update.query('feedback', kft.sys_id);
	if (kft_update.next()) {
		kft_update.feedback_task_type = 7;
        kft_update.update();
	}
})(current, previous);

 

This solution effectively allows me to have a kb_feedback_task record generated every time a user submits an Knowledge Article for publishing or retiring. While also being scalable and modular enough that I could limit this to a specific Knowledge Base or attach additional functionality merely by editing the created business rules. 

View solution in original post

1 REPLY 1

TREE_
Tera Contributor

So I figured this out. The workflow on this isn't immediately obvious, but I think the intended way to produce kb_feedback_task records in ServiceNow is to via a kb_feedback record. 

 

If you have yet to, you will need to enable the, "Create actionable feedback task when an article is flagged," property found in Knowledge Properties (Knowledge -> Administration -> Properties). This enables the use of the OOB 'Knowledge Feedback Task Creation' business rule that will become a dependency of this workflow. 

 

To enable the use of approvals - also necessary for the workflow solution I developed - you will need to set the publish and retire workflows to 'Knowledge - Approval Publish' and 'Knowledge - Approval Retire' respectively. You can manage your knowledge bases from: Knowledge -> Administration -> Knowledge Bases.

 

I then opted to create two new advanced business rules for when an article to submitted for Publishing and when its submitting for Retiring. When you press Publish or Retire on a checked out article, it puts the article in the states, 'Review' and 'Pending Retirement' respectively. Hence, I opted to create a business rule that will trigger when our Knowledge Article's state changes to either 'Review' or 'Pending Retirement.' 

 

For the purposes of my kb_feedback_task record tracking, I created a new choice option for the 'Feedback Task Type' (feedback_task_type) field called, "Knowledge Submissions." This choice option has the value '7.'

 

I've attached screenshots of the business rule setup for the Publishing business rule. The retirement business rule is basically the same but modifying the respective state conditions, and then changing the data you want placed into your KFT. No configuration is needed under the 'Actions' tab as we are not changing any states from the kb_knowledge table. 

br1.png

br2.png

 

The script for the advanced business rule script is as follows: 

(function executeRule(current, previous /*null when async*/) {
	// This section generates a kb_feedback record which will then be handled by the
	// Knowledge Feedback Task Creation business rule to create the kb_feedback_task record.
	var kft = new GlideRecord('kb_feedback');
	kft.initialize();
	kft.user = gs.getUserID();
	kft.article = current.sys_id;
	kft.reason = 'Article Published';	// Custom Comment
	kft.comments = gs.getMessage("{0} has been submitted for publishing and needs to be reviewed then approved/rejected.",current.number);
	kft.insert();

	// Because I wanted to customize the kb_feedback_task record after it's insertion, we run a query
	// for the newly generated task and if it exists then we update it's feedback_task_type field.
	// For this I created a custom feedback_task_type value named, "Knowledge Submissions."
	// If you leave this section out, your kb_feedback_task field will default to "User Feedback."
	var kft_update = new GlideRecord('kb_feedback_task');
	kft_update.query('feedback', kft.sys_id);
	if (kft_update.next()) {
		kft_update.feedback_task_type = 7;
        kft_update.update();
	}
})(current, previous);

 

This solution effectively allows me to have a kb_feedback_task record generated every time a user submits an Knowledge Article for publishing or retiring. While also being scalable and modular enough that I could limit this to a specific Knowledge Base or attach additional functionality merely by editing the created business rules.