forked from H-E-R-DAO/newsletter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappendArticleTask.gs
More file actions
54 lines (50 loc) · 2.14 KB
/
Copy pathappendArticleTask.gs
File metadata and controls
54 lines (50 loc) · 2.14 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
/**
* Logs a generated draft to the Drafts Log sheet in this spreadsheet.
* If the sheet doesn't exist, it automatically creates it with headers.
*
* Columns: Date | Draft Title | Google Doc Link | Status | Form Row
* "Form Row" is hidden — it stores the row number in the Form Responses sheet
* so failed drafts can be reprocessed automatically.
*
* @param {string} title - title of the draft (or failure label)
* @param {string} docUrl - link to the generated Google Doc (empty string on failure)
* @param {string} [status] - '✅ Done' (default) or '⚠️ FAILED'
* @param {number} [formRowNum] - row index in the Form Responses sheet (for retry)
* @return {number} row index of the logged entry
*/
function logDraftToSheet(title, docUrl, status, formRowNum) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetName = Config.DRAFT_LOG_SHEET_NAME || 'Drafts Log';
var sheet = ss.getSheetByName(sheetName);
if (!sheet) {
sheet = ss.insertSheet(sheetName);
_initLogHeaders(sheet);
}
var today = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd HH:mm:ss');
var rowStatus = status || '✅ Done';
var rowFormRef = formRowNum || '';
sheet.appendRow([today, title, docUrl, rowStatus, rowFormRef]);
return sheet.getLastRow();
}
/**
* Applies bold headers and column widths to a freshly created log sheet.
* Hides column E (Form Row) — it's internal plumbing, not for editors.
* @param {Sheet} sheet
*/
function _initLogHeaders(sheet) {
sheet.appendRow(['Date', 'Draft Title', 'Google Doc Link', 'Status', 'Form Row']);
sheet.getRange(1, 1, 1, 5).setFontWeight('bold');
sheet.setColumnWidth(1, 140);
sheet.setColumnWidth(2, 280);
sheet.setColumnWidth(3, 380);
sheet.setColumnWidth(4, 120);
sheet.setColumnWidth(5, 80);
sheet.hideColumns(5); // Form Row is internal — keep the UI clean
}
/**
* Developer utility to test logging to the local spreadsheet.
*/
function testLogDraftToSheet() {
var row = logDraftToSheet('TEST – Universal Newsletter Draft', 'https://docs.google.com/document/d/example/edit');
Logger.log('Logged test draft at row ' + row + ' in the "Drafts Log" sheet.');
}