0% found this document useful (0 votes)
2 views

code

This Google Apps Script provides functionality for a Task Manager within Google Sheets, allowing users to open a sidebar and a modal dialog for editing and deleting tasks. It includes functions to retrieve tasks, update them, delete selected tasks, and sync updates with individual assignee sheets. The script also retrieves a list of assignees from a designated sheet for task assignment purposes.

Uploaded by

apoorv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

code

This Google Apps Script provides functionality for a Task Manager within Google Sheets, allowing users to open a sidebar and a modal dialog for editing and deleting tasks. It includes functions to retrieve tasks, update them, delete selected tasks, and sync updates with individual assignee sheets. The script also retrieves a list of assignees from a designated sheet for task assignment purposes.

Uploaded by

apoorv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Full Google Apps Script (Code.

gs) with Edit & Delete Popup Functionality

function onOpen() {
let ui = SpreadsheetApp.getUi();
ui.createMenu("Task Manager")
.addItem("Open Task Sidebar", "openTaskSidebar")
.addItem("Open Edit/Delete Popup", "openPopup")
.addToUi();
}

function openTaskSidebar() {
let html = HtmlService.createHtmlOutputFromFile("Sidebar")
.setTitle("Task Manager")
.setWidth(300);
SpreadsheetApp.getUi().showSidebar(html);
}

function openPopup() {
let html = HtmlService.createHtmlOutputFromFile("Popup")
.setWidth(400)
.setHeight(400);
SpreadsheetApp.getUi().showModalDialog(html, "Edit/Delete Task");
}

function getTasksForPopup() {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tasks");
let data = sheet.getDataRange().getValues();
let tasks = [];
for (let i = 1; i < data.length; i++) {
tasks.push({ id: data[i][0], name: data[i][1], assignedTo: data[i][2], status:
data[i][3], timeline: data[i][4], approvalReq: data[i][5] });
}
return tasks;
}

function updateTask(taskId, updatedData) {


let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tasks");
let data = sheet.getDataRange().getValues();

for (let i = 1; i < data.length; i++) {


if (data[i][0] == taskId) {
sheet.getRange(i + 1, 2, 1, updatedData.length).setValues([updatedData]);
syncTaskWithAssigneeSheet(taskId, updatedData);
break;
}
}
}

function deleteTasks(taskIds) {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tasks");
let data = sheet.getDataRange().getValues();

for (let i = data.length - 1; i > 0; i--) {


if (taskIds.includes(data[i][0])) {
sheet.deleteRow(i + 1);
}
}
}
function syncTaskWithAssigneeSheet(taskId, updatedData) {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let mainSheet = ss.getSheetByName("Tasks");
let data = mainSheet.getDataRange().getValues();

let assignee = updatedData[0];


let assigneeSheet = ss.getSheetByName(assignee);
if (!assigneeSheet) {
assigneeSheet = ss.insertSheet(assignee);
assigneeSheet.appendRow(["Task ID", "Task Name", "Assigned To", "Status",
"Timeline", "Approval Req"]);
}

for (let i = 1; i < data.length; i++) {


if (data[i][0] == taskId) {
let row = assigneeSheet.getDataRange().getValues().findIndex(r => r[0] ==
taskId) + 1;
if (row > 0) {
assigneeSheet.getRange(row, 2, 1,
updatedData.length).setValues([updatedData]);
}
break;
}
}
}

function getAssignees() {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Assignees");
return sheet.getRange("A2:A").getValues().flat().filter(String);
}

You might also like