What is this?
...
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.
...
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 Form
Add KB Article Template to the related records section.
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); } } } |
Script Include
We need to determine if there's child templates or not.
Code Block | ||
---|---|---|
| ||
var YaleAjax = Class.create();
YaleAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
hasChildTemplates: function() {
template = this.getParameter('sysparm_template');
gr = new GlideRecord('sys_template');
gr.get(template);
if(gr.next != '' || gr.next_child != ''){
// If there's child templates return true
return true;
}else{
// There are no child templates
return false;
}
},
_privateFunction: function() { // this function is not client callable
}
}); |
UI Action
This handles the case when there are tasks on the template and the record needed to be saved first.
Action Name : apply_my_template
Code Block | ||
---|---|---|
| ||
action.setRedirectURL(current);
current.applyTemplate(current.u_kb_article_template.u_template.name);
current.update(); |
References
https://community.servicenow.com/thread/143298
...