-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCategorySpecificSpreadsheetPopulator.gs
82 lines (70 loc) · 3.34 KB
/
CategorySpecificSpreadsheetPopulator.gs
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
var DataProcessing = DataProcessing || {};
DataProcessing.CategorySpecificSpreadsheetPopulator = (function () {
/**
* Uses the category specific sheet to determine which range should be retrieved from the
* spreadsheet for adding.
*
* @param {GoogleAppsScript.Spreadsheet.Sheet} sheet the sheet to get the range from.
* @param {Object[]} dataToExport the data to be exported to the specificed sheet.
* @returns {GoogleAppsScript.Spreadsheet.Range} the range where the data should be added.
* @private
*/
var _getDataRangeFromCategorySpecificSheet = function (sheet, dataToExport) {
// Given that we are appending data, we want to start 1 row after the current last row
var sheetRowStart = sheet.getLastRow() + 1;
var rowCount = dataToExport.length;
var dataColumnCount = dataToExport[0].length;
var sheetDataRange = sheet.getRange(sheetRowStart, 1, rowCount, dataColumnCount);
return sheetDataRange;
};
var _setFormulasForData = function (sheet, dataToExport) {
var formulaBaseRowIndex = sheet.getLastRow() + 1;
var followUpTypeIndex = 20;
var lcStudyLeaderIndex = 25;
var regionIndex = 26;
var ministryAreaIndex = 27;
dataToExport.forEach(function (row, index) {
var formulaRowIndex = formulaBaseRowIndex + index;
row[followUpTypeIndex] = '= if(Q' + formulaRowIndex + '="yes", "Bridge, ", "") & '
+ 'if(R' + formulaRowIndex + '="yes", "BS, ", "") & if(S' +
formulaRowIndex + '="yes", "E-List, ", "")';
row[lcStudyLeaderIndex] =
'=iferror(VLOOKUP(V' + formulaRowIndex + ', LeadershipCommunity!A2:F, 4), "")';
row[regionIndex] =
'=iferror(VLOOKUP(V' + formulaRowIndex + ', LeadershipCommunity!A2:F, 5), "")';
row[ministryAreaIndex] =
'=iferror(VLOOKUP(V' + formulaRowIndex + ', LeadershipCommunity!A2:F, 6), "")';
});
};
/**
* Takes the processed master sheet and populates the data into all of the category specific
* sheets.
*
* @param {Model.ProcessedMasterSheet} processedMasterSheet the processed master sheet to use to
* populate category specific sheets.
* @private
*/
var _populateCategorySpecificSpreadsheets = function (processedMasterSheet) {
processedMasterSheet.categories.forEach(function (category) {
var categorySpecificSheet =
processedMasterSheet.categorySpecificSpreadsheets[category.categoryName];
if (categorySpecificSheet === undefined || categorySpecificSheet.dataToExport === []) {
return;
}
var sheet = categorySpecificSheet.spreadsheet.getSheets()[0];
_setFormulasForData(sheet, categorySpecificSheet.dataToExport);
var sheetDataRange =
_getDataRangeFromCategorySpecificSheet(sheet, categorySpecificSheet.dataToExport);
sheetDataRange.setValues(categorySpecificSheet.dataToExport);
var assignmentIdentifierRange = categorySpecificSheet.spreadsheet.getRange(
'LeadershipCommunity!A2:A');
var assignmentIdentifiersRule = SpreadsheetApp.newDataValidation()
.requireValueInRange(assignmentIdentifierRange)
.build();
sheet.getRange('V2:V').setDataValidation(assignmentIdentifiersRule);
});
};
return {
populateCategorySpecificSpreadsheets: _populateCategorySpecificSpreadsheets
};
})();