Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Email is been used to set the cc and subjed where we got from the UI Page and this will be attached to the Notification to run dymanically


(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {


// In this we get the data in the 4th parameter so that we use the parm2 to get the object of data and the used in the certain purpose

var obj = JSON.parse(event.parm2);
email.addAddress("cc", obj.cc);
email.setSubject(obj.subject);

template.print(" <h5 style='margin: 0px;'>Hi Team,</h5><br><p>Details are : </p>" + obj.body);

})(current, template, email, email_action, event);
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Notificaiton for this proble

Table : Incident (incident)

When to Send
Send when - Event is fried
Event name - SendEamilInForm

Who will receive
Event parm 1 contains recipient - True

What it will contain
// This will hold the email script which we use to populate the subjec and the body.
Message HTML - ${mail_script:IncidentFormScript}
Email template - Unsubscribe and Preferences
Content type - HTML only

*/

// Name of the Email Script will be populated when the notification has been triggered.
${mail_script:IncidentFormScript}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Send Email On Form for every Record

Script Type: UI Action, Table: incident, Form button: True, Client: True, Show update: True, OnClick: functionName()

Script Type: UI Page Category: General

Script Type: Email Script

Event Registry : Table: incident, Fired by: UI Page, Event Name: SendEmailInForm

Notification : Table: incident, Type: EMAIL, Category: Uncategorized,

Goal: To Send Email on Form Directly by population some field and then customize the body and trigger it.

Walk through of code: So to send the Email directly on each and every record there will be a UI Action which will help to populate the UI Page which we use some field to be populate in the UI Page directly to the particulat HTML content and these are the fields will be populate (Caller Email as the To and then Short Description as the Subjet of the Email) and othe field will be CC and Body which the user want to decide what data can be filled out and then send.

<img width="1908" height="417" alt="UIAction_INC_fomr" src="https://github.com/user-attachments/assets/0ec5afb2-8375-41b8-a346-4fe5ee55913f" />


UI Page - This will have 5 components
1. To Caller
2. CC
3. Subject
4. Body
5. Send button

<img width="804" height="434" alt="UI Page Email template" src="https://github.com/user-attachments/assets/1d1ff563-7430-4ec3-b391-9f55912ad4e1" />



Once the Send button has been triggered this will call the Processing Script where the event will trigger once this will call the Event Registry event("SendEmailInForm") which we use for this problem statment.Where the Notification will trigger when the Event is fried and then for the email content we uset the Email Script which dynamic content will be populated which we got from the UI page as the event parm2 and then will send the email to the respective caller.

<img width="1477" height="759" alt="Notification_Contains" src="https://github.com/user-attachments/assets/ddc91bbf-aeba-4de2-8db4-2fba9d823fba" />
<img width="1522" height="377" alt="Notification_Receive" src="https://github.com/user-attachments/assets/b2934470-6c90-4b52-be6d-7f2397b8609a" />
<img width="1705" height="952" alt="Notification1" src="https://github.com/user-attachments/assets/d74cfe59-dd3e-42b7-b95a-b0134169b679" />



<img width="808" height="278" alt="Email Preview" src="https://github.com/user-attachments/assets/75d4c1ca-36e8-4e01-8d37-6f1fad0ecfc1" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This function will creat the model object and then route to the UI page which we configured to show the field details to fill by the user

/*
Table- Incident (incident)
Form button - True
Client -True
Show Update - True
Onclick - Function name (sendEmail)



*/
function sendEmail(){
var modalT = new GlideModal("SendEmailEvent", false, 1200);
modalT.setTitle("Send Email");
modalT.setPreference("sysparm_sys_id", g_form.getUniqueValue());
modalT.render();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.email-form {
background: #fff;
padding: 20px 25px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
width: 850px;
}

.email-form h2 {
text-align: center;
margin-bottom: 15px;
color: #333;
}

label {
display: block;
margin-top: 10px;
font-weight: bold;
color: #555;
}

input[type="text"],
input[type="email"],
textarea {
width: 100%;
padding: 8px;
margin-top: 5px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
font-size: 14px;
}

textarea {
resize: none;
height: 100px;
}

button {
width: 100%;
background-color: #007bff;
color: white;
padding: 10px;
border: none;
border-radius: 5px;
margin-top: 15px;
cursor: pointer;
font-size: 16px;
}

button:hover {
background-color: #0056b3;
}
</style>
<body>

<!-- Getting the sys_id From the Form UI View -->
<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().get('sysparm_sys_id')" />


<!-- GlideRecord Query to current INC Ticket -->

<g:evaluate jelly="true" object="true" var="jvar_gr">
var gr_inc = new GlideRecord('incident');
gr_inc.addQuery('sys_id', '${jvar_sysId}');
gr_inc.query();
gr_inc;
</g:evaluate>

<j:while test="${gr_inc.next()}">
<j:set var="jvar_short_desc" value="${gr_inc.getValue('short_description')}"></j:set>
<j:set var="jvar_num" value="${gr_inc.getValue('number')}"></j:set>
<j:set var="jvar_email" value="${gr_inc.caller_id.email}"></j:set>
</j:while>


<g:ui_form>
<!-- <h2>Send Email</h2> -->

<label for="to">To Caller:</label>
<input type="email" id="to" name="to" value="${jvar_email}" placeholder="Caller recipient email" />

<label for="bcc">CC:</label>
<input type="email" id="cc" name="cc" placeholder="Enter CC email" />

<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject" value="${jvar_short_desc}" placeholder="Short Description will be poulated" />

<label for="body">Body:</label>
<textarea id="body" name="body" placeholder="Body to send email" >${jvar_num}</textarea>

<button type="submit">Send</button>
</g:ui_form>
</body>

</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Getting the value from the HTML and the make the body and trigger the event for further process.

var obj={};
obj.body = body.toString();
obj.cc = cc.toString();
obj.subject = subject.toString();

// Event Trigger and passing the paramenters
/*
Parm 1 : will have the to receipient
Parm 2 : will have the cc, subject and body
*/
gs.eventQueue("SendEmailInForm",current,to,JSON.stringify(obj));
Loading