Apply template to Incident OnChange
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2009 09:45 AM
Hi.
I am a rank newbie at javascript and SNC--apologies in advance if this sounds dumb.
When the help desk is working on a ticket, they may need to change an existing ticket to P1, or to open a new P1. When this happens, we want to apply a template to that existing ticket instantly--the template sets the 'additional comments' field to have a bunch of questions that the help desk needs to answer before submitting the ticket.
So I read the wiki article on creating templates and even the snippet about applying them with scripts, but apparently I am dense. I have created a script that runs against the priority field on the incident form, of type onChange. It is active and it is also marked 'global'. The script is:
//apply the P1 template when the priority is changed to 1. function onChange(control, oldValue, newValue) { if (oldValue != newValue && newValue == 1) current.applyTemplate("p1_Template_for_Help_Desk"); }
I have tried this with an extra set of curly braces around the applyTemplate statement the way the code checker wants me to do, but it doesn't help. I have also tried removing the if statement so it applies the template no matter how the priority changes. That doesn't seem to help either. Originally there were spaces in the template name--I removed those to make sure they weren't the problem, and nothing changed.
I am sure there must be some newbie mistake in here, I'd really appreciate a pointer.
Note: There is another piece of script with the same settings and the same If statement that pops up an alert. The alert is working, but the applyTemplate doesn't. Do I need to use something other than 'current'? Is it not OK to have to essentially identical scripts run on the same event (the action being the only difference)?
Thanks very much for your time and help.
shris
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2010 01:56 AM
One other thing I've done is use a Client SIDE UI Action that then calls a FUNCTION IN A SERVER SIDE UI ACTION
UI Action code: (CLIENT SIDE - CLIENT FIELD TICKED
Onclick: applyTemplate()
SCRIPT:
function applyTemplate()
{
//Check Template Has been Selected
if (g_form.getValue('u_template') == '')
{ alert("Please Select A Template");
}
else
{
//Turn Off Mandatory Fields Check
g_form.checkMandatory=false;
//NOTE: Code below is calling the Server side Apply Template UI Action
gsftSubmit(gel('Apply_Template'));
}
}
SERVER SIDE UI ACTION (CLIENT NOT TICKED)
ACTION NAME: Apply_Template
SCRIPT:
if (current.u_template.name != '')
{
var ltemplate = Packages.com.glide.script.Template.getByName(current.u_template.name);
if (ltemplate)
{
current.setNewGuidValue(current.sys_id.toString()); // this is necessary to keep the template code from setting a new sys_id value for the record
ltemplate.setDoInsert(false);
ltemplate.apply(current);
current.u_created_from_template = true;
current.update();
action.setRedirectURL(current);
action.setReturnURL(current);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2010 01:38 PM
Mark,
I'm trying to call a kb submission template using applyTemplate in a Client Script. It doesn't seem to be working. Is there anything I need to do to enable this for Submissions or any reason why this might not work? I'm just using a pretty simple OnLoad script:
function onLoad() {
applyTemplate(ed6c5acd0a0a3c6001aa768091e10fda);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2010 01:40 PM
You're providing a string to the applyTemplate function so you probably just need to add quotes around that sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2010 01:59 PM
WOo Hoo! That was it! Thanks Mark!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2010 04:02 AM
For some reason I can not find the sys_ID's for the template I have made. Anyone know the best way to pull the sys ID?