Add email to Watch List via Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2011 11:57 AM
Within an Incident if the the Priority is 1 or 2 I need to add the Service Desk's email to a Watch List. I can't seem to get it to work. Here is the script I am trying:
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (!isLoading) { if(newValue != '') { var pr = g_form.getValue('priority'); var wList = current.u_itil_watch_list; var eMail = "it.servicedesk@myemail.com"; if ((pr == '1') || (pr == '2')){ wList = wList + "," + eMail; current.u_itil_watch_list = wList; current.update(); } } } }
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2011 10:40 AM
I see your doing this via client script, you may want to make a business rule instead.
Also try this:
var wList = current.u_itil_watch_list.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2011 12:14 PM
Yes, as the previous comment suggested, you would be better doing this in a business rule - you don't have access to "current" in a client script. Set the Condition on the business rule to current.priority.changesTo(1)||current.priority.changesTo(2)
Also, you may like to check that you don't add the servicedesk email to the watch list each time the priority changes from 1 to 2 or vice versa, or you may end up with the same address several times. I've done something similar to this using a script similar to the following:
var list = current.watch_list.toString();
var array = list.split(",");
var len = array.length;
/* Get the sys_id of the User you want to add */
var usr = new GlideRecord('sys_user');
usr.addQuery('email', "the email address you want to add");
usr.query();
usr.next();
/* See if the User is already on the list */
var onList = false;
for (var i=0; i<len; i++) {
if (array<i> == usr.sys_id) {
onList = true;
}
}
if (!onList) {
array[len] = usr.sys_id;
}
current.watch_list.setValue(array.join());
Hope this helps.
Brian Broadhurst (TeamUltra Ltd.)