提问人:Dummy1234 提问时间:11/17/2023 更新时间:11/18/2023 访问量:25
Google 脚本 - 在 gmail 中从 gsheet 中的活动单元格创建任务
Google script - Create task in gmail from active cell in gsheet
问:
我有在第 17 行生成错误的脚本 也许有人可以帮助我解决这个问题 我不知道如何修复它并使其正常工作
ReferenceError: Gmail is not defined
createTaskFromCell @ TaskCreator.gs:17
function createTaskFromCell() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var activeCell = sheet.getActiveCell();
var cellContent = activeCell.getValue();
var taskTitle = cellContent;
var taskDescription = "Please fill details";
var taskDueDate = getNextWorkingDay();
var task = {
title: taskTitle,
notes: taskDescription,
due: taskDueDate,
};
var userId = 'me';
var response = Gmail.Users.Tasks.insert(task, userId);
Logger.log('Created task with ID: ' + response.id);
}
function getNextWorkingDay() {
var today = new Date();
var nextDay = new Date(today);
while (!isWorkingDay(nextDay)) {
nextDay.setDate(nextDay.getDate() + 1);
}
return nextDay;
}
function isWorkingDay(date) {
var day = date.getDay();
return day !== 0 && day !== 6; // Exclude weekends (Saturday and Sunday)
}
答:
0赞
Linda Lawton - DaImTo
11/18/2023
#1
ReferenceError:未定义 Gmail
可以通过添加 gmail 服务来修复
但是我认为你做错了。您应该使用任务而不是 gmail
/**
* Adds a task to a tasklist.
* @param {string} taskListId The tasklist to add to.
* @see https://developers.google.com/tasks/reference/rest/v1/tasks/insert
*/
function addTask(taskListId) {
// Task details with title and notes for inserting new task
let task = {
title: 'Pick up dry cleaning',
notes: 'Remember to get this done!'
};
try {
// Call insert method with taskDetails and taskListId to insert Task to specified tasklist.
task = Tasks.Tasks.insert(task, taskListId);
// Print the Task ID of created task.
console.log('Task with ID "%s" was created.', task.id);
} catch (err) {
// TODO (developer) - Handle exception from Tasks.insert() of Task API
console.log('Failed with an error %s', err.message);
}
}
评论