-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.gs
More file actions
153 lines (130 loc) · 4.27 KB
/
Code.gs
File metadata and controls
153 lines (130 loc) · 4.27 KB
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
// SHEET NAMES
const SHEET_FMS = "FMS";
const SHEET_DOER = "Doer_Name";
const SHEET_USER = "User";
function doGet() {
return HtmlService.createHtmlOutputFromFile("Index")
.setTitle("Help Ticket Dashboard")
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
// --- LOGIN FUNCTION ---
function doLogin(email, password) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(SHEET_USER);
const data = sheet.getDataRange().getValues();
for (let i = 1; i < data.length; i++) {
let row = data[i];
if (
String(row[2]).trim().toLowerCase() ==
String(email).trim().toLowerCase() &&
String(row[1]).trim() == String(password).trim()
) {
return {
success: true,
username: row[0],
role: row[3] || "User",
};
}
}
return { success: false };
}
// --- DROPDOWN DATA ---
function getDropdownData() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(SHEET_DOER);
const data = sheet.getDataRange().getValues();
let raisedByList = [];
let pcList = [];
for (let i = 1; i < data.length; i++) {
if (data[i][1]) raisedByList.push(data[i][1]);
if (data[i][2]) pcList.push(data[i][2]);
}
return {
raisedBy: [...new Set(raisedByList)],
pc: [...new Set(pcList)],
};
}
// --- SUBMIT NEW TICKET ---
function submitTicket(form) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(SHEET_FMS);
// Generate UID
let nextId = "001";
const lastRow = sheet.getLastRow();
if (lastRow >= 5) {
const lastUid = sheet.getRange(lastRow, 2).getValue();
let num = parseInt(lastUid);
if (!isNaN(num)) nextId = (num + 1).toString().padStart(3, "0");
}
const timestamp = new Date();
sheet.appendRow([
timestamp, // A
nextId, // B
form.raisedBy, // C
form.pcAccountable, // D
form.issue, // E
form.problemSolver, // F
"",
"",
"",
"", // G, H, I, J (Follow Up)
"",
"",
"",
"", // K, L, M, N (Problem Solving)
]);
return "Ticket Raised Successfully! UID: " + nextId;
}
// --- GET OPEN TICKET UIDS ---
function getOpenTicketUIDs() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(SHEET_FMS);
const lastRow = sheet.getLastRow();
if (lastRow < 5) return [];
const data = sheet.getRange(5, 2, lastRow - 4, 1).getValues();
return data.flat().filter((uid) => uid !== "");
}
// --- SUBMIT FOLLOW UP (Columns G, H, I, J) ---
function submitFollowUp(form) {
// Start Column G is index 7
return updateDataInSheet(form, 7, "Follow-Up");
}
// --- SUBMIT PROBLEM SOLVING (Columns K, L, M, N) ---
function submitProblemSolving(form) {
// Start Column K is index 11
return updateDataInSheet(form, 11, "Problem Solving");
}
// --- HELPER FUNCTION TO UPDATE ROW ---
function updateDataInSheet(form, startCol, typeName) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(SHEET_FMS);
const data = sheet.getDataRange().getValues();
// Find Row by UID
for (let i = 4; i < data.length; i++) {
// Data starts at Row 5 (index 4)
if (String(data[i][1]) == String(form.ticketUid)) {
const rowNum = i + 1; // 1-based row index
// Update basic 3 columns (Planned, Actual, Status)
sheet.getRange(rowNum, startCol).setValue(form.planned); // Planned
sheet.getRange(rowNum, startCol + 1).setValue(form.actual); // Actual
sheet.getRange(rowNum, startCol + 2).setValue(form.status); // Status
// Handle "Follow-Up" Delay (4th column in section)
if (typeName === "Follow-Up" && form.delay) {
sheet.getRange(rowNum, startCol + 3).setValue(form.delay);
}
// Handle "Problem Solving" Desired Date (4th column in section)
// Problem Solving starts at 11 (K). 11+3 = 14 (N).
if (typeName === "Problem Solving" && form.desiredDate) {
sheet.getRange(rowNum, startCol + 3).setValue(form.desiredDate);
}
return typeName + " Updated for UID: " + form.ticketUid;
}
}
return "Error: UID Not Found";
}
// --- VIEW DATA (ADMIN) ---
function getDashboardData() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(SHEET_FMS);
return sheet.getDataRange().getDisplayValues();
}