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
‎07-17-2009 10:37 AM
Any luck in figuring this out? I can't get my template to apply either?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2009 11:28 AM
Hi.
No, not especially. I have abandoned this method, though I know there's a wiki about using a client script to call a business rule, and in the business rule you can use 'current'.
What we are doing instead is creating a separate table to house the category list and the field settings we want to use on our tickets. We will have over 300 different types of tickets, many of them replicated in three languages. With that volume of items, the table is deemed more manageable than a template list. And with a client script I can set the fields just fine. No 'applyTemplate' method needed, just a setValue..
shris

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2010 03:54 PM
***SNC confirmed today this does not work in Client Scripts and have removed the content from the Wiki.***
A Business Rule is the way to go. Look to another forum article and comments by Mark Stanger. -Bill
INT1530373: applyTemplate(sys_id of template to apply) in client script
User instance: SNC instance -
________________________________________
2010-05-14 09:34:58 - Don GoodliffeAdditional Comments
Removed that from the wiki. Does not apply to client scripts.
________________________________________
2010-05-13 22:37:17 - Bill Collins (Nashco)Additional Comments
I don't believe this works as described in the wiki:
Apply a Template in Script
You can apply a template to a record in a javascript. You would use:
-For a client script...
applyTemplate(sys_id of template to apply);
http://wiki.service-now.com/index.php?title=Creating_a_Template#Apply_a_Template_in_script
I have tried these variations:
g_form.applyTemplate(sys_id of template to apply)
g_form.applyTemplate("Name of Template")
current.applyTemplate(sys_id of template to apply)
current.applyTemplate("Name of Template")
gs.applyTemplate(sys_id of template to apply)
gs.applyTemplate("Name of Template")
Ref:MSG2053951

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2010 09:52 PM
You can apply a template in a client script. I use this syntax all the time.
Client script...
//Apply the selected template
applyTemplate(template_sys_id);
I use this call in an onChange client script that I've included in an update set here.
http://www.servicenowguru.com/system-definition/advanced-templates/