Save a change template as a bookmark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2014 07:23 AM
Hello,
We had created a change template to be used by our Network Staff. They asked if there is an easier way to utilize the template rather than creating a new change, rt click to apply template, and then select needed template.
My thought was it would be great to have the template as a book mark item. Thus, they click on the bookmark and it would open a new change using the proper template thus populating the needed fields.
Any ideas of how the template can be utilized with possibly just one click?
Thanks,
Patty
- Labels:
-
Service Mapping

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2014 07:32 AM
Hi Patty,
You may find the below article as helpful
http://www.servicenowguru.com/system-definition/advanced-templates/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2014 07:36 AM
Another direction to go would be to create a module that applies a template to a new record as referenced in this wiki article. You could create a section of modules for templates and let your users drag the ones they want to their edge.
Creating a Template - Module - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2014 07:48 AM
Hi,
In this example you can both add shortcut keys / quickkeys and single click links at the bottom of a form for applying templates. I did this back in 2011 so there are room for many improvements in this solution, but ill post it as inspiration.
If you add a custom div-element in an *annotation field, in this case a div with ID="templatesContainer", you could populate it with something like this:
Make a onLoad script, add a gliderecord query as var templates to the below code and let it loop through to assign and display shortcut keys as clickable links.
I dont normally dont recommend using document.getElementById, but since we defined the div container our self its unlikely to become obsolete. However, i recommend to use prototype library if any modifications to the form must be done from client side.
var objTemplatesDiv = document.getElementById("templatesContainer");
if(objTemplatesDiv) {
while(templates._next()) { //Should be _next (Oct 11 rel)
addKeys(i, templates.template_sys_id);
divContent = divContent + "Ctrl+" + i + " : <a id=\"template_ " + i + "\" href=\"javascript: applyTemplate('" + templates.template_sys_id + "');\">" + templates.template_name + "</a><br/>";
i++;
}
objTemplatesDiv.innerHTML = divContent;
function addKeys(thisNumber, templateId) {
shortcut.add('Ctrl+' + thisNumber,function() {
var t = new TemplateRecord(templateId);
t.apply();
},{disable_in_input: false});
}
}
"Install" the quick keys ui script.
/**
* <a href="http://www.openjs.com/scripts/events/keyboard_shortcuts/<br />
" title="http://www.openjs.com/scripts/events/keyboard_shortcuts/<br />
">http://www.openjs.com/scripts/events/keyboard_shortcuts/<br />
</a> * Version : 2.01.B
* By Binny V A
* License : BSD
*/
shortcut = {
'all_shortcuts':{},//All the shortcuts are stored in this array
'add': function(shortcut_combination,callback,opt) {
//Provide a set of default options
var default_options = {
'type':'keydown',
'propagate':false,
'disable_in_input':false,
'target':document,
'keycode':false
}
if(!opt) opt = default_options;
else {
for(var dfo in default_options) {
if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
}
}
var ele = opt.target;
if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
var ths = this;
shortcut_combination = shortcut_combination.toLowerCase();
//The function to be called at keypress
var func = function(e) {
e = e || window.event;
if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
var element;
if(e.target) element=e.target;
else if(e.srcElement) element=e.srcElement;
if(element.nodeType==3) element=element.parentNode;
if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
}
//Find Which key is pressed
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code).toLowerCase();
if(code == 188) character=","; //If the user presses , when the type is onkeydown
if(code == 190) character="."; //If the user presses , when the type is onkeydown
var keys = shortcut_combination.split("+");
//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
var kp = 0;
//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
var shift_nums = {
"`":"~",
"1":"!",
"2":"@",
"3":"#",
"4":"$",
"5":"%",
"6":"^",
"7":"&",
"8":"*",
"9":"(",
"0":")",
"-":"_",
"=":"+",
";":":",
"'":"\"",
",":"<",
".":">",
"/":"?",
"\\":"|"
}
//Special Keys - and their codes
var special_keys = {
'esc':27,
'escape':27,
'tab':9,
'space':32,
'return':13,
'enter':13,
'backspace':8,
'scrolllock':145,
'scroll_lock':145,
'scroll':145,
'capslock':20,
'caps_lock':20,
'caps':20,
'numlock':144,
'num_lock':144,
'num':144,
'pause':19,
'break':19,
'insert':45,
'home':36,
'delete':46,
'end':35,
'pageup':33,
'page_up':33,
'pu':33,
'pagedown':34,
'page_down':34,
'pd':34,
'left':37,
'up':38,
'right':39,
'down':40,
'f1':112,
'f2':113,
'f3':114,
'f4':115,
'f5':116,
'f6':117,
'f7':118,
'f8':119,
'f9':120,
'f10':121,
'f11':122,
'f12':123
}
var modifiers = {
shift: { wanted:false, pressed:false},
ctrl : { wanted:false, pressed:false},
alt : { wanted:false, pressed:false},
meta : { wanted:false, pressed:false} //Meta is Mac specific
};
if(e.ctrlKey) modifiers.ctrl.pressed = true;
if(e.shiftKey) modifiers.shift.pressed = true;
if(e.altKey) modifiers.alt.pressed = true;
if(e.metaKey) modifiers.meta.pressed = true;
for(var i=0; k=keys[i],i<keys.length; i++) {
//Modifiers
if(k == 'ctrl' || k == 'control') {
kp++;
modifiers.ctrl.wanted = true;
} else if(k == 'shift') {
kp++;
modifiers.shift.wanted = true;
} else if(k == 'alt') {
kp++;
modifiers.alt.wanted = true;
} else if(k == 'meta') {
kp++;
modifiers.meta.wanted = true;
} else if(k.length > 1) { //If it is a special key
if(special_keys[k] == code) kp++;
} else if(opt['keycode']) {
if(opt['keycode'] == code) kp++;
} else { //The special keys did not match
if(character == k) kp++;
else {
if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
character = shift_nums[character];
if(character == k) kp++;
}
}
}
}
if(kp == keys.length &&
modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
modifiers.shift.pressed == modifiers.shift.wanted &&
modifiers.alt.pressed == modifiers.alt.wanted &&
modifiers.meta.pressed == modifiers.meta.wanted) {
callback(e);
if(!opt['propagate']) { //Stop the event
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = false;
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
return false;
}
}
}
this.all_shortcuts[shortcut_combination] = {
'callback':func,
'target':ele,
'event': opt['type']
};
//Attach the function with the event
if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
else ele['on'+opt['type']] = func;
},
//Remove the shortcut - just specify the shortcut and I will remove the binding
'remove':function(shortcut_combination) {
shortcut_combination = shortcut_combination.toLowerCase();
var binding = this.all_shortcuts[shortcut_combination];
delete(this.all_shortcuts[shortcut_combination])
if(!binding) return;
var type = binding['event'];
var ele = binding['target'];
var callback = binding['callback'];
if(ele.detachEvent) ele.detachEvent('on'+type, callback);
else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
else ele['on'+type] = false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2014 08:00 AM
Found some more old code with some more pretty formatting to use for inpiration for an onLoad client script.
Please note that this example calls a custom client callable script include for ajax query.
//Dan Berglin 2011-02-08
function onLoad() {
var objTemplatesDiv = document.getElementById("templatesContainer");
var divContent = '<br/><table class="wide"><tbody><tr class="list_banner_line"><td colspan="5"/></tr></tbody></table><h3>Quick keys:</h3><table><tr><td>';
var key = 1;
var altKey = 1;
var altEnd = 9;
var charCodeStart = 68;
var charCodeEnd = 90;
var getTemplates = new GlideAjax('returnTemplates');
getTemplates.addParam('sysparm_name','queryTemplates');
getTemplates.addParam('sysparm_table','u_call');
getTemplates.addParam('sysparm_order','name');
getTemplates.getXML(templateParse);
function templateParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var arrTemplates = answer.split("|");
for (var i = 0; i < arrTemplates.length-1; i++) {
var templateRowSplit = arrTemplates[i].split(":");
var templateName = templateRowSplit[0];
var templateSysId = templateRowSplit[1];
if(key < 10) {
addThisKey(key, templateSysId);
divContent = divContent + "Ctrl+" + key + " : <a id=\"template_ " + key + "\" href=\"javascript: applyTemplate('" + templateSysId + "');\">" + templateName + "</a></br>";
}
else if (altKey < altEnd) {
if (i < 10) {
//Add a new column
divContent = divContent + "</td><td style=\"padding-left: 40px\" valign=\"top\">";
}
addThisKey("Ctrl+Alt+" + altKey, templateSysId);
divContent = divContent + "Ctrl+Alt+" + altKey + " : <a id=\"template_ " + altKey + "\" href=\"javascript: applyTemplate('" + templateSysId + "');\">" + templateName + "</a><br/>";
altKey++;
}
key++;
}
//Add static keys and another column
divContent = divContent + "</td><td style=\"padding-left: 40px\" valign=\"top\">";
//CTRL+S
divContent = divContent + "Ctrl+S : <a href=\"javascript: log_call();\">Log call</a><br/>";
shortcut.add("Ctrl+S",function() {
log_call();
},{disable_in_input: false});
//Global keys already defined
divContent = divContent + "Ctrl+Q : <a href=\"javascript: parent.gsft_main.location.href = \'/u_call.do?sys_id=-1\';\">New Call</a><br/>";
divContent = divContent + "Ctrl+Alt+Q : <a href=\"javascript: window.open(\'/u_call.do?sys_id=-1\', \'_blank\');\">New Call in new Tab</a><br/>";
//Write to doc
objTemplatesDiv.innerHTML = divContent + "</td></tr></table>";
enableCallerIframe();
}
function addThisKey(thisKey, sys_id) {
shortcut.add("Ctrl+" + thisKey,function() {
var t = new TemplateRecord(sys_id);
t.apply();
},{disable_in_input: false});
}
function enableCallerIframe() {
var callerContainer = document.getElementById("callerContainer");
var iFrameHeight = g_fontSizePreference.replace("pt","")*6+95;
if (callerContainer.innerHTML.length == 0) {
callerContainer.innerHTML = '<br/><div><table class="wide"><tbody><tr class="list_banner_line"><td colspan="5"/></tr></tbody></table><iframe scrolling="no" class="gsft_full" seamless="seamless" id="user_form" frameborder="0" name="user_form" style="position: relative; left: -5px; top: 0px; overflow-y: hidden; overflow-x: hidden; overflow: hidden; height: ' + iFrameHeight + 'px; " title="User Content"></iframe>';
}
}
}