Time Trigger on Google Sheet Add On

我与影子孤独终老i 提交于 2021-02-08 11:24:04

问题


I have created a Google Apps Script and now want to publish it as a Google Sheet add on.

The way script should work is to fetch some details from an API on daily basis (via the time trigger) and send notification to the installer if any new information is found in the data fetched via the API.

When people install this add-on, I want it to run automatically for them everyday, and send them email when changes are found as above.

Is this doable with google sheet add on?


回答1:


Yes it is feasible, only thing is users need to Click on to the Addon menu once (For the first time only) in order to Grant the necessary permissions. On this click you can start Trigger for everyday.

Here's the sample,

function onInstall() {
  onOpen(); 
}
function onOpen() {
  var ui = SpreadsheetApp.getUi();
  // Or DocumentApp or FormApp.
  ui.createMenu('Schedule')
  .addItem('Start Schedule', 'menuItem3')
  .addToUi();
}

function menuItem3() {
  createTrigger();
}

function createTrigger()
{
    ScriptApp.newTrigger('startProcess')
    .timeBased()
    .everyDays(1)
    .create(); 
}


function startProcess(){
// Add your processing logic here. e.g. send notifications.
}


来源:https://stackoverflow.com/questions/50382884/time-trigger-on-google-sheet-add-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!