How to write a script to create a Known error KB article
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 04:15 AM
Need a script, "when problem record is marked as known Error, create a Known error KB article and map the problem source"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 04:59 AM
Hello @jayaprakash1998
Sure, you can automate the creation of a Known Error KB article when a problem record is marked as a Known Error. Here's a sample script that you can use in a Business Rule or Scripted REST API:
(function executeRule(current, previous /*null when async*/) {
// Check if the problem record is marked as a Known Error
if (current.problem_state == 'Known Error') {
// Create a new KB article
var kb = new GlideRecord('kb_knowledge');
kb.initialize();
kb.short_description = current.short_description;
kb.text = current.description;
kb.knowledge_base = 'Knowledge'; // Set this to your Knowledge Base
kb.workflow_state = 'published'; // Set this to your desired state
kb.u_problem = current.sys_id; // Map the problem source
kb.insert();
}
})(current, previous);
Here's the summary:
- Check if the problem record is marked as a Known Error.
- If it is, create a new KB article.
- Set the short description of the KB article to the short description of the problem record.
- Set the text of the KB article to the description of the problem record.
- Set the Knowledge Base of the KB article to your Knowledge Base.
- Set the workflow state of the KB article to your desired state.
- Map the problem source to the KB article by setting the u_problem field of the KB article to the sys_id of the problem record.
- Insert the new KB article into the database.
Please note that you need to replace 'Knowledge' and 'published' with your actual Knowledge Base and desired state. Also, 'u_problem' is a custom field that you need to create in the 'kb_knowledge' table to store the sys_id of the problem record.
Please mark it Correct and Hit Like if you find this helpful!
