Skip to content

Commit d0d0e92

Browse files
authored
Add files via upload
Send Email On Form for every Record
1 parent 9c77f47 commit d0d0e92

File tree

5 files changed

+181
-0
lines changed

5 files changed

+181
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// 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
2+
3+
4+
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
5+
/* Optional EmailOutbound */
6+
email, /* Optional GlideRecord */ email_action,
7+
/* Optional GlideRecord */
8+
event) {
9+
10+
11+
// 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
12+
13+
var obj = JSON.parse(event.parm2);
14+
email.addAddress("cc", obj.cc);
15+
email.setSubject(obj.subject);
16+
17+
template.print(" <h5 style='margin: 0px;'>Hi Team,</h5><br><p>Details are : </p>" + obj.body);
18+
19+
})(current, template, email, email_action, event);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Notificaiton for this proble
3+
4+
Table : Incident (incident)
5+
6+
When to Send
7+
Send when - Event is fried
8+
Event name - SendEamilInForm
9+
10+
Who will receive
11+
Event parm 1 contains recipient - True
12+
13+
What it will contain
14+
// This will hold the email script which we use to populate the subjec and the body.
15+
Message HTML - ${mail_script:IncidentFormScript}
16+
Email template - Unsubscribe and Preferences
17+
Content type - HTML only
18+
19+
*/
20+
21+
// Name of the Email Script will be populated when the notification has been triggered.
22+
${mail_script:IncidentFormScript}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// 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
2+
3+
/*
4+
Table- Incident (incident)
5+
Form button - True
6+
Client -True
7+
Show Update - True
8+
Onclick - Function name (sendEmail)
9+
10+
11+
12+
*/
13+
function sendEmail(){
14+
var modalT = new GlideModal("SendEmailEvent", false, 1200);
15+
modalT.setTitle("Send Email");
16+
modalT.setPreference("sysparm_sys_id", g_form.getUniqueValue());
17+
modalT.render();
18+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
3+
<style>
4+
body {
5+
font-family: Arial, sans-serif;
6+
background-color: #f8f9fa;
7+
display: flex;
8+
justify-content: center;
9+
align-items: center;
10+
height: 100vh;
11+
margin: 0;
12+
}
13+
14+
.email-form {
15+
background: #fff;
16+
padding: 20px 25px;
17+
border-radius: 8px;
18+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
19+
width: 850px;
20+
}
21+
22+
.email-form h2 {
23+
text-align: center;
24+
margin-bottom: 15px;
25+
color: #333;
26+
}
27+
28+
label {
29+
display: block;
30+
margin-top: 10px;
31+
font-weight: bold;
32+
color: #555;
33+
}
34+
35+
input[type="text"],
36+
input[type="email"],
37+
textarea {
38+
width: 100%;
39+
padding: 8px;
40+
margin-top: 5px;
41+
border: 1px solid #ccc;
42+
border-radius: 5px;
43+
box-sizing: border-box;
44+
font-size: 14px;
45+
}
46+
47+
textarea {
48+
resize: none;
49+
height: 100px;
50+
}
51+
52+
button {
53+
width: 100%;
54+
background-color: #007bff;
55+
color: white;
56+
padding: 10px;
57+
border: none;
58+
border-radius: 5px;
59+
margin-top: 15px;
60+
cursor: pointer;
61+
font-size: 16px;
62+
}
63+
64+
button:hover {
65+
background-color: #0056b3;
66+
}
67+
</style>
68+
<body>
69+
70+
<!-- Getting the sys_id From the Form UI View -->
71+
<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().get('sysparm_sys_id')" />
72+
73+
74+
<!-- GlideRecord Query to current INC Ticket -->
75+
76+
<g:evaluate jelly="true" object="true" var="jvar_gr">
77+
var gr_inc = new GlideRecord('incident');
78+
gr_inc.addQuery('sys_id', '${jvar_sysId}');
79+
gr_inc.query();
80+
gr_inc;
81+
</g:evaluate>
82+
83+
<j:while test="${gr_inc.next()}">
84+
<j:set var="jvar_short_desc" value="${gr_inc.getValue('short_description')}"></j:set>
85+
<j:set var="jvar_num" value="${gr_inc.getValue('number')}"></j:set>
86+
<j:set var="jvar_email" value="${gr_inc.caller_id.email}"></j:set>
87+
</j:while>
88+
89+
90+
<g:ui_form>
91+
<!-- <h2>Send Email</h2> -->
92+
93+
<label for="to">To Caller:</label>
94+
<input type="email" id="to" name="to" value="${jvar_email}" placeholder="Caller recipient email" />
95+
96+
<label for="bcc">CC:</label>
97+
<input type="email" id="cc" name="cc" placeholder="Enter CC email" />
98+
99+
<label for="subject">Subject:</label>
100+
<input type="text" id="subject" name="subject" value="${jvar_short_desc}" placeholder="Short Description will be poulated" />
101+
102+
<label for="body">Body:</label>
103+
<textarea id="body" name="body" placeholder="Body to send email" >${jvar_num}</textarea>
104+
105+
<button type="submit">Send</button>
106+
</g:ui_form>
107+
</body>
108+
109+
</j:jelly>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Getting the value from the HTML and the make the body and trigger the event for further process.
2+
3+
var obj={};
4+
obj.body = body.toString();
5+
obj.cc = cc.toString();
6+
obj.subject = subject.toString();
7+
8+
// Event Trigger and passing the paramenters
9+
/*
10+
Parm 1 : will have the to receipient
11+
Parm 2 : will have the cc, subject and body
12+
*/
13+
gs.eventQueue("SendEmailInForm",current,to,JSON.stringify(obj));

0 commit comments

Comments
 (0)