-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail_noreply.js
223 lines (174 loc) · 7.64 KB
/
mail_noreply.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
function emailNotify()
{
//Basic Initialization
//Change name to the name of your Spreadsheet
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Hypercare").activate();
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
var count = 0;
//Basic Variables
var i = 0;
var m=0;
var name;
var sheets = SpreadsheetApp.getActive().getSheets();
var numer = SpreadsheetApp.getActive().getNumSheets();
//Check for Sheet Existence
for(i=0; i<numer; i++)
{
name = sheets[i].getName();
if(name == "Template")
{
m = 1;
break;
}
else
{
continue;
}
}
//If sheet Exists
if(m == 1)
{
SpreadsheetApp.getActive().setActiveSheet(SpreadsheetApp.getActive().getSheetByName('Template'), true);
}
else
{
//Set message accordingt to your Needs.
SpreadsheetApp.getActive().insertSheet(SpreadsheetApp.getActive().getActiveSheet().getIndex() + 1).activate();
SpreadsheetApp.getActive().getActiveSheet().setName('Template');
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(1, 1).setValue("Hello {name},\n\nThis is a Reminder that the {application} raised by {raise} with GIS stakeholder {GIS}, is DUE in {days} days.\nNature of Issue: {noi}\n\nBest Regards,\nXacrolyte");
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(2, 2).setValue("Hello {name},\n\nThis is a Reminder that the {application} raised by {raise} with GIS stakeholder {GIS}, is DUE in {days} days.\nNature of Issue: {noi}\n\nBest Regards,\nXacrolyte");
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(3, 3).setValue("Hello {name},\n\nThis is a Reminder that the {application} assigned to {assign}, raised by {raise} with GIS stakeholder {GIS} is DUE in {days} days.\nNature of Issue: {noi}\n\nBest Regards,\nXacrolyte");
}
//Template Init
var templateTextBuild = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(1, 1).getValue();
var templateZTextBuild = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(2, 2).getValue();
var templateY1TextBuild = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(3, 3).getValue();
var templateY2TextBuild = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(3, 3).getValue();
//Qouta var and check
var qoutaLeft = MailApp.getRemainingDailyQuota();
//Logger.log("Dailt qouta left = " + qoutaLeft);
//If qouta is not available
if((lr-1)>qoutaLeft)
{
Browser.msgBox('You have ' + qoutaLeft + ' mail qouta left and you are trying to send ' + (lr-1) + ' mails');
}
//If qouta is available
else
{
//Sends Mails to all
for(var i=2; i<=lr; i++)
{
//Raised On Date
var raisedDate = ss.getRange(i, 4).getValue();
//Logger.log(raisedDate);
//Planned Closure Date
var plannedCDate = ss.getRange(i, 8).getValue();
//Logger.log(plannedCDate);
//Actual Closure Date
var actualCDate = ss.getRange(i, 9).getValue();
//Logger.log(actualCDate + "ACTUAL");
//Current Date
var now = new Date();
//Difference
var diff = plannedCDate - now;
var dayDiff = parseInt(diff * 0.00000001157407);
//Logger.log(diff);
//Logger.log(dayDiff);
//If Planned-Closure Date is approaching
if(dayDiff>0 && actualCDate == "")
{
Logger.log("Number of days passed = " + dayDiff);
//Column Assigned To Email
var currentAssignedEmail = ss.getRange(i, 10).getValue();
//Column Assigned To
var currentAssigned = ss.getRange(i, 10).getValue();
//Column Application Name
var currentApplication = ss.getRange(i, 1).getValue();
//Column Raised By Email
var currentRaisedNameEmail = ss.getRange(i, 2).getValue();
//Column Raised By
var currentRaisedName = ss.getRange(i, 2).getValue();
//Column GIS Stakeholder Email
var currentGISNameEmail = ss.getRange(i, 3).getValue();
//Column GIS Stakeholder
var currentGISName = ss.getRange(i, 3).getValue();
//Column Nature of Issue
var currentNOI = ss.getRange(i, 6).getValue();
//Column Issue Decription
var currentDesc = ss.getRange(i, 5).getValue();
var messageBody = templateTextBuild.replace("{name}", currentAssigned)
.replace("{application}",currentApplication)
.replace("{raise}",currentRaisedName)
.replace("{GIS}",currentGISName)
.replace("{days}",dayDiff)
.replace("{noi}",currentNOI);
var subjectLine = "Reminder: "+ currentApplication + " is DUE";
count += 1;
Logger.log(count);
Logger.log(subjectLine);
Logger.log(messageBody);
MailApp.sendEmail(currentAssignmentEmail, subjectLine, messageBody);
}//End If
else if(dayDiff <= 0 && actualCDate == "" )
{
Logger.log("Number of days passed = " + dayDiff);
//Column Assigned To Email
var currentAssignedEmail = ss.getRange(i, 10).getValue();
//Column Assigned To
var currentAssigned = ss.getRange(i, 10).getValue();
//Column Application Name
var currentApplication = ss.getRange(i, 1).getValue();
//Column Raised By Email
var currentRaisedNameEmail = ss.getRange(i, 2).getValue();
//Column Raised By
var currentRaisedName = ss.getRange(i, 2).getValue();
//Column GIS Stakeholder Email
var currentGISNameEmail = ss.getRange(i, 3).getValue();
//Column GIS Stakeholder
var currentGISName = ss.getRange(i, 3).getValue();
//Column Nature of Issue
var currentNOI = ss.getRange(i, 6).getValue();
//Column Issue Decription
var currentDesc = ss.getRange(i, 5).getValue();
//Mail to Assigned
var messageBody = templateZTextBuild.replace("{name}", currentAssigned)
.replace("{application}",currentApplication)
.replace("{raise}",currentRaisedName)
.replace("{GIS}",currentGISName)
.replace("{days}",dayDiff)
.replace("{noi}",currentNOI);
var subjectLine = "Reminder: "+ currentApplication + " is DUE";
count += 1;
Logger.log(count);
Logger.log(subjectLine);
Logger.log(messageBody);
MailApp.sendEmail(currentAssignedEmail, subjectLine, messageBody);
//Mail to GIS Stakeholder
var messageBody2 = templateY2TextBuild.replace("{name}", currentGISName)
.replace("{application}",currentApplication)
.replace("{assign}", currentAssigned)
.replace("{raise}",currentRaisedName)
.replace("{GIS}",currentGISName)
.replace("{days}",dayDiff)
.replace("{noi}",currentNOI);
Logger.log(count);
Logger.log(subjectLine);
Logger.log(messageBody2);
MailApp.sendEmail(currentGISNameEmail, subjectLine, messageBody1);
//Mail to Rasied Name
var messageBody1 = templateY1TextBuild.replace("{name}", currentRaisedName)
.replace("{application}",currentApplication)
.replace("{assign}", currentAssigned)
.replace("{raise}",currentRaisedName)
.replace("{GIS}",currentGISName)
.replace("{days}",dayDiff)
.replace("{noi}",currentNOI);
Logger.log(count);
Logger.log(subjectLine);
Logger.log(messageBody1);
//MailApp.sendEmail(currentRaisedNameEmail, subjectLine, messageBody2);
}
}
}
}