Using incident template when creating incident from knowledge article

Bennie dijkslag
Tera Contributor

When creating an incident from a knowledge article, how to pass a template for the incident, depending on the knowledge article?

 

So each knowledge article (in theory) could have their own specific incident template.

4 REPLIES 4

Community Alums
Not applicable

Hi @Bennie dijkslag Knowledge Articles in ServiceNow can be configured to have their own specific Incident Template. This means that when a user creates an incident from a Knowledge Article, the incident will automatically use the template associated with that Knowledge Article.

 

Implementation:

1. Add a Reference Field for Incident Template to Knowledge Article:

  • Go to Knowledge > Knowledge Articles.
  • Open the Knowledge Article form.
  • Add a reference field called Incident Template that references the Incident Template [incident_template] table.

2. Create a UI Action for Creating an Incident:

  • Go to System Definition > UI Actions.
  • Create a new UI Action on the Knowledge Article form (e.g., "Create Incident").
  • Ensure the Action name is set to something like create_incident.
  • Set the Condition for when the button should appear, for example:
    javascript
    Copy code
    current.template != '' // Only show the button if a template is selected.

3. Script for the UI Action:

In the script of the UI Action, you will create a new Incident and set its Template field based on the Knowledge Article’s reference to the Incident Template.

Here’s an example script for the UI Action:

 


(function executeAction() { // Get the Incident Template from the current Knowledge Article
var templateId = current.incident_template; // Assuming you added the field 'incident_template' to the Knowledge Article record if (templateId) { // Create a new Incident
var newIncident = new GlideRecord('incident');
newIncident.initialize(); // Apply the template to the Incident
newIncident.template = templateId; // You can also set other incident fields as needed
newIncident.short_description = 'Incident created from Knowledge Article: ' + current.short_description; newIncident.description = current.text; // Assuming you want to include the Knowledge Article content in the incident // Insert the new Incident
var incidentSysId = newIncident.insert(); // Optionally, you can redirect to the new Incident action.setRedirectURL(newIncident); }
else { // If no template is found, show an error or handle the case
gs.addErrorMessage('No Incident Template associated with this Knowledge Article.');
}
})();

4. Create or Configure Incident Templates:

  • Make sure that you have Incident Templates set up in the Incident Template [incident_template] table.
  • Each template can define default values for Incident fields, such as Category, Priority, Impact, etc.

5. Test the UI Action:

  • Once everything is configured, navigate to a Knowledge Article that has an associated Incident Template.
  • Click the Create Incident button.
  • The new Incident should be created with the template applied.

Thanks, i will go ahead and try this

Bennie dijkslag
Tera Contributor

I'd like to send the KB-number as template name in the url for "create incident" on knowledge article. Adding a UI action only works when the article is opened from the module, not from the search results.

 

Been searching more in the community and found this; adding "&sysparm_template=$[HTML:knowledgeRecord.number]" to the create incident link will do what i'm looking for.

 

Apart from the fact that, when the template does not exist, no other fields will be populated, even if you add them in the link.

 

The link is set in the system property: glide.knowman.create_incident_link