【问题标题】:If a cell in an incoming row from a Google Form has a certain value, then run a script function如果来自 Google 表单的传入行中的单元格具有特定值,则运行脚本函数
【发布时间】:2020-08-30 02:24:53
【问题描述】:

我想在 Google 表格中获取新条目(来自 Google 表单),并根据 B 列中的响应对它们运行某个触发器。我已经写出了代码(它将信息发送到Google Doc模板),并建立了触发器,但它不区分B列中的数据。

这是我正在研究的一个非常通用的版本:FormWorkbookDoc

这是我得到的代码:

function Bob(e) {
  var timestamp = e.values[0];
  var name = e.values[1];
  var awesome = e.values[2];
  
  var file = DriveApp.getFileById('1BxK26Yim0-nAVQW5FcQ59q3Uxe2qm9EhClLE1thSdMU'); 
  var folder = DriveApp.getFolderById('149gm5Voa3tthmv66cF5kJmf3bf2zj-VA')
  
  var copy = file.makeCopy(name, folder); 
  
  var doc = DocumentApp.openById(copy.getId()); 
  
  var body = doc.getBody(); 
  
  body.replaceText('{{Timestamp}}', timestamp); 
  body.replaceText('{{Name}}', name);  
  body.replaceText('{{Awesome}}', awesome); 
  
  doc.saveAndClose(); 
}

所以本质上,如果 B 列显示 Bob,那么触发器将启动并且函数将运行。如果它显示 Joe,那么单独的触发器将运行不同的功能(我还没有设置,但假设它只不过是一个复制粘贴工作)。我的猜测是,在我的函数运行之前,它只需要几行 if 语句的形式,但我对此很陌生。

谢谢

【问题讨论】:

  • 函数Bob(e)的触发设置是什么?

标签: google-apps-script triggers google-docs


【解决方案1】:

使用 if 语句添加条件,即,

function Bob(e){
  if(e.values[1] === 'Bob'){
    // Add here what you want you function does when the corresponding cell of Column B is equal to "Bob"
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    相关资源
    最近更新 更多