How can I generate a notification from a UI action button?

CharlesR1
Kilo Guru

Hello,

I am trying to set up a new UI Action called 'Send MTI Notification' on our incident form. When this button is clicked I want it to generate a pop-up window which contains the exact information that will go out in the email notification. Once the user hits the OK button, I want an event on the UI action to kick off the email notification and populates the email notification based on the pre-populated fields on the incident form.

I have already set up the UI Action button on the form that generates a 'Send MTI Notification' button when certain conditions are met. I have also set up the event 'incident.sendmtinotification', and an associated Notification, however I don't know which script I need on the UI Action in order to activate the event when the button is pressed.

If possible, can anyone please point me in the direction of the script I need to write, and also some information as to how I can create the popup window to preview the email before it is sent?

Thanks very much,

Charles

1 ACCEPTED SOLUTION

CharlesR1
Kilo Guru

Sure - these are the steps we took to get this up and running...


I have selected only the fields 'Incident Number', 'Short Description' and 'Causing System' on our Incident table for the example below -

These are the steps to set it up:

1) Go to UI actions, and create a new one for the email button . Enter a script based on the one below - Choose the values you want to add to the email (this is the top half of script - note that some fields require 2 lines of scripting to retrieve the values, if these are a choice/reference field, for example, such as 'u_causing_system') and the popup window (this is the bottom half of the script). Chose the name of your new popup window, and replace 'popup1' with this new name on the line 'var dialog = new GlideDialogWindow("popup1")'
....................................
function sendEmail(){

var incident_number = g_form.getValue("number"); var short_description = g_form.getValue("short_description");
var u_causing_system__value = g_form.getValue("u_causing_system_");
var u_causing_system_ = g_form.getOption('u_causing_system_',
u_causing_system__value).text;

//Initialize and open the Dialog Window

var dialog = new GlideDialogWindow("popup1"); dialog.setSize(1200,1200); dialog.setTitle("MTI Notification Preview - Incident In Progress");

dialog.setPreference("short_description", short_description); dialog.setPreference("incident_number", incident_number); dialog.setPreference("u_causing_system_", u_causing_system_);

dialog.render();

action.setRedirectURL(current);

}
....................................

2) Go to UI Pages and create your new popup window with your chosen title for 'popup1'. Enter a script based on the one below, and amend the values in the HTML script to match those shown in the UI action. The top of the HTML field retrieves the values shown in the UI action, and the bottom half presents these values onto the popup window. You can amend the format of the window here, along with the action buttons visible.

....................................
<?xml version="1.0" encoding="utf-8"?>
xmlns:g2="null">

expression="RP.getWindowProperties().get('short_description')" /> expression="RP.getWindowProperties().get('incident_number')" /> expression="RP.getWindowProperties().get('u_causing_system_')" />

value="${jvar_incident_number}"/>

Incident Title: ${jvar_short_description}
Incident Number: ${jvar_incident_number}
Causing System: ${jvar_u_causing_system_}     id="send_email">Send id="cancel_button">Cancel

....................................
-The Client Script should be:
....................................

function onSubmit() {
//GlideDialogWindow.get().destroy();
return true;
}

function cancel() {
var c = gel('cancelled');
c.value = "true";
GlideDialogWindow.get().destroy();
return false;
}
....................................
-Then scroll down to the 'Processing Script':
....................................

var sysid = '';
var gr = new GlideRecord('incident');
gr.addQuery('number', inc_number);
gr.query();
if(gr.next()){
if (cancelled != "true") {
gs.eventQueue('XXXX', gr, gs.getUserID(), gs.getUserName()); } sysid = gr.sys_id; }

response.sendRedirect('incident.do?sys_id='+sysid);
gs.addInfoMessage('YYYY.');

....................................
-Amend 'XXXX' to be a new event name (eg, 'Email1') for the event to be called. Amend 'YYYY' to be the info message you want to be displayed when the email has been sent.

3) Go to the Registry and create a new event based on this, called XXXX or 'Email1'

4) Go to the Notifications section, and create a new notification based on the new event created in (3), making sure you select 'Event is fired:Email1/XXXX.

That should be it.


View solution in original post

51 REPLIES 51

Hi Charles,



Does this UI Page only pop up for the person logged in? We'd like for a customer to submit a Priority 1 INC and everyone in a particular group would see the UI Page.



Any thoughts/recommendations?



Thanks!



Matthew


Hi Matthew,



Yes it's only for the current logged-in user. I'm not sure exactly what you're after here - When the person logged in clicks the UI action, the preview UI page pops up to show all the values in all the fields that will we included in the email. It would be odd for it to appear out of the blue for other users, when they are working on other tasks. Perhaps I'm missing your point .



Charles


Hey Charles,


Thanks for the quick reply. We've got an operations center (like a help desk center). Priority 1 and 2 emails go out when one is created but the downside is that these emails get lost and the help desk team may not always be aware of tickets coming in that are Priority 1 or 2 (if they are helping other users).



We'd like the UI Page to come across to everyone in the help desk center. At least this makes them aware of a new ticket that came in. We can create an error alert but we are hoping for something more 'in your face' when these type of tickets come in. Hope this helps-



Matthew


Hi Matthew,



Is there any reason why you wouldn't just use a new module for use by the Operations Center (limited by role), and use Mark's 'Outlook style' module counts to highlight when there are new tickets to be dealt with?



http://www.servicenowguru.com/system-ui/outlook-style-module-counts/



If you really want a UI page on creation of a new ticket then I'm sure we can look into that


Charles


HI Charles,



I've considered a separate module with a gauge that indicates if a new Pri 1 or 2 comes in with a refresh rate of 10 seconds or something like that. Helsinki has a real-time indicator that we could use (in the future of course).



I like Mark's idea, but it would be a risk. We'd have to re implement something when we go to Geneva as this functionality won't work in Geneva.



As of now, I think the gauge is our best bet. Thanks for your help!



Matthew