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

lindac
Kilo Explorer

This sound very interesting. I can see this being used for us. Please keep me in the loop. Thank you.


Hi lindac,

I now have the steps that we took to create this feature successfully. Let me know if you would like me to send these to you.

Charles


Hi Charles,

I have activated my contact option.

Thank you,


Hi Charles,

This sounds like exactly what I'm working on. Could you send me the script you used?

Thanks!
Carrie


Hello Charles,

Can you share this with me too?
I am very interested as well.


Thanks
Sander Bungener