...
...
...
Add sys_template to glide.ui.permitted_tables
client script
...
What is this?
The help desk relies heavily upon the application of templates to their incidents. They search the knowledge base and when they find the appropriate KB article they use the 'Attach to Incident' button to indicate that they used the knowledge base. It will also apply a template to the ticket if one is attached to the KB, which saves time and makes for consistent tickets. There was a requirement to allow for tasks on templates to be applied as well, which complicates things a little. Here's how it was implemented below:
Added Template field to Knowledge article form
glide.ui.permitted_tables
Add sys_template as a permitted table, otherwise people won't be able to see the templates to attach to the knowledge article.
Roles
template_editor, template_editor_group or template_editor_global must be granted to allow people to alter and view the templates as well.
Knowledge Properties
Set the target of the knowledge article to a custom field on incident
KnowledgeFunctions UI script
In order for templates with tasks to work, we need to skip the check to see if the record was saved. We simply commented out the check here. This UI script appears to be the same in Fuji, but we'll need to check this going forward.
Code Block | ||
---|---|---|
| ||
function attachIncident2(x, target) {
if (self.opener) {
/*
var lastSaved = self.opener.document.getElementById("onLoad_sys_updated_on").value;
if (!lastSaved){
self.close();
var err = (gel('error_msg')!=null)?gel('error_msg').value:"Invalid action: Record needs to be saved first";
self.opener.g_form.addErrorMessage(err);
return false;
}
*/
var e = self.opener.document.getElementById("sys_uniqueValue")
var task = e.value; |
Incident Client Script
This fires on change of the u_kb_article_template field. We do things a little differently if we determine that there's tasks or other child templates on the template we're using. If there are child templates we have to save the record first, if not we can just apply the template.
Code Block | ||
---|---|---|
| ||
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue == '') return; var template = g_form.getReference('u_kb_article_template').u_template; var ga = new GlideAjax('YaleAjax'); ga.addParam('sysparm_name','hasChildTemplates'); ga.addParam('sysparm_template',template); ga.getXML(hasTemplate); function hasTemplate(response) { answer = response.responseXML.documentElement.getAttribute("answer"); if(answer == 'true'){ // If there's child templates we have to save the record first g_form.checkMandatory = false; gsftSubmit(null, g_form.getFormElement(), 'apply_my_template'); }else{ // If there's no child record, no need to save before applyTemplate(template); } } } |
References
https://community.servicenow.com/thread/143298