I am attempting to create something that will pull out a certain number of tasks per category and put them on my daily task list. I currently have it set by priorty only but I want to include a setting for urgency so that even if something is marked lower in priority if it is really urgent that will get pulled first. I am not even sure where to begin to add that factor into the decision making process.
I have very little experience so I apologize in advance at how rough this question is and how overly complex I made the initial code.
function movePriorities() {
var sourceSheetName = 'Tasks';
var destinationSheetName = 'To Do';
var priorityColumnIndex = 2; // Assuming the priority column is the first column (A)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sourceSheet = ss.getSheetByName(sourceSheetName);
var destinationSheet = ss.getSheetByName(destinationSheetName);
// Get all data from the source sheet
var data = sourceSheet.getDataRange().getValues();
// Group data by priority
var priorityGroups = groupByPriority(data, priorityColumnIndex);
// Move 5 rows from each priority group to the destination sheet
for (var priority in priorityGroups) {
// Skip the first two rows as headers
var rowsToMove = priorityGroups[priority].slice(2).filter(row => row[priorityColumnIndex - 1] !== ''); // Adjust index to 0-based
rowsToMove = rowsToMove.slice(0, 5);
for (var i = 0; i < rowsToMove.length; i++) {
destinationSheet.appendRow(rowsToMove[i]);
}
}
}
// Helper function to group data by priority
function groupByPriority(data, priorityColumnIndex) {
var groups = {};
for (var i = 2; i < data.length; i++) { // Start from the third row
var priority = data[i][priorityColumnIndex - 1]; // Adjust index to 0-based
if (!groups[priority]) {
groups[priority] = [];
}
groups[priority].push(data[i]);
}
return groups;
}