Last active
December 20, 2018 21:05
-
-
Save phillypb/ded5071cb3ba6b0167653328b42bdf76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getStartDate() { | |
// get 'Plan' sheet | |
var planSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Plan'); | |
// get 'Plan' sheet data range | |
var planDataRange = planSheet.getDataRange(); | |
// get 'Plan' sheet data values | |
var planData = planDataRange.getValues(); | |
// get number of last row of data in 'Plan' sheet | |
var planLastRow = planSheet.getLastRow(); | |
// loop through each Assignee from 'Plan' sheet to get relevant details (skipping row headers) ********* | |
for (i=1; i<planLastRow; i++) { | |
// check Assignee cell is not blank before proceeding | |
// i = row, 6 = column - as is 2-D array | |
if (planData[i][6]) { | |
Logger.log('Assignee cell is not blank'); | |
// get current cell of 'Assignee' column row. Add 1 to row value 'i' otherwise is a row behind | |
var getCell = planDataRange.getCell([i+1], [7]); | |
// Date Start ************************************************************************************** | |
// get corresponding 'Date' for Assignee via 'new Date' so is a date object (correctly formatted) | |
var date = new Date(planData[i][1]); | |
// add 16 hours to the date: for 4pm start time of event | |
date.setHours(16); | |
// specifically format date so appropriate for feeding into event | |
var dateStart = Utilities.formatDate(date, "GMT+1", "MMMM dd yyyy' 'HH:mm"); | |
Logger.log(dateStart); | |
//create end date for event - add 16 hours 30 mins to the original date for 4:30pm finish | |
date.setHours(16); | |
date.setMinutes(30); | |
// specifically format date so appropriate for feeding into event | |
var dateEnd = Utilities.formatDate(date, "GMT+1", "MMMM dd yyyy' 'HH:mm"); | |
Logger.log(dateEnd); | |
// Date End **************************************************************************************** | |
} // end of 'if' for checking Assignee cell not blank | |
else {Logger.log('Assignee cell is blank')}; | |
} // end of 'i' loop through each Assignee ************************************************************* | |
} | |
function onOpen() { | |
SpreadsheetApp.getUi() | |
.createMenu('Menu') | |
.addItem('Email Assignees', 'getStartDate') // label for menu item, name of function to run. | |
.addToUi(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment