简体   繁体   English

每次我尝试运行它时,我的“来自电子表格 - 提交表单”触发器都会被禁用 - 我如何找出原因?

[英]My "From spreadsheet - On form submit" trigger is getting disabled every time I try to run it - how do I find out why?

I have a Google form that collects reddit usernames in a Google sheet.我有一个 Google 表单,可以在 Google 表格中收集 reddit 用户名。 I have a script to check whether the username doesn't exist (ie https://www.reddit.com/user/<username> gives a 404) or is banned (username looked up against a list var banned_users = [...] ).我有一个脚本来检查用户名是否不存在(即https://www.reddit.com/user/<username>给出 404)或被禁止(用户名在列表中查找var banned_users = [...] )。 If it is non-existent or banned, I mark the row orange.如果它不存在或被禁止,我将行标记为橙色。 Here's the script:这是脚本:

function validateUser() {
   var spreadsheet = SpreadsheetApp.openById(sheet_id);
   var sheet = SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[0]);
   var last_row_number = sheet.getLastRow();
   var reddit_username = sheet.getRange(last_row_number, 2).getValue();
   var reddit_username_cell = sheet.getRange(last_row_number, 2);
   var reddit_username_row = sheet.getRange(last_row_number, 1, 1, 19);

   if (banned_users.indexOf(reddit_username) != -1) {
    reddit_username_cell.setNote('This user is banned.');
    reddit_username_row.setBackground('#ff9900')
  } else {
     var url = 'https://www.reddit.com/user/' + reddit_username.slice(2) // Get rid of the leading 'u/'
     var options = {
        'muteHttpExceptions': true,
        'followRedirects': true
     };
     var response = UrlFetchApp.fetch(url, options);
     var http_code = response.getResponseCode();

     if (http_code == '404') {
       reddit_username_cell.setNote('This user does not exist.');
       reddit_username_row.setBackground('#ff9900') // #ff9900 is default orange
    }
  }
}

This script works when I manually run the function.当我手动运行该函数时,此脚本有效。 It successfully marks banned or non-existent users when I make a form submission and trigger it from the script editor.当我提交表单并从脚本编辑器触发它时,它成功地标记了禁止或不存在的用户。 However when I add a trigger to run it on form submit, and then make a form submission, it gets disabled:但是,当我添加触发器以在表单提交时运行它,然后进行表单提交时,它会被禁用:

触发器禁用 未知原因

I don't understand why.我不明白为什么。 There is no email explaining the reason or logs showing that it ran at all.没有电子邮件解释原因或日志显示它根本运行。 How do I find out why this trigger is getting disabled and how do I fix it?如何找出此触发器被禁用的原因以及如何修复它? Thank you!谢谢!

When running it from a standalone script (not Sheets-bound) I get the following error:从独立脚本(非 Sheets-bound)运行时,出现以下错误:

Please select an active spreadsheet first.请先选择一个活动电子表格。 (line 11, file "Code") (第 11 行,文件“代码”)

upon executing the line:在执行该行时:

var sheet = SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[0]);

Triggers do run scripts in a standalone fashion too, so I suggest you avoid using active sheets.触发器也以独立方式运行脚本,因此我建议您避免使用active表。 Instead, you can simply replace above line of code for the following:相反,您可以简单地将上面的代码行替换为以下内容:

var sheet = spreadsheet.getSheets()[0];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谁能帮我找出为什么我的 p5 草图每次运行时都会崩溃? - Can anybody help me find out why my p5 sketch is crashing every time I run it? 每次我使用 javascript 提交表单时,我的 LI 都会重复 - My LI are duplicating every time I submit my form with javascript 每次我尝试运行我的代码时都会出错 - Error coming every time I try to run my code 在提交表单之前,如何避免我的AJAX请求被取消? - How do I keep my AJAX request from getting cancelled before form submit? JS表单:如何在每次单击“提交”时不将新的数组推入数组而将推入到数组中? - JS Form: How do I push() into an array, without creating a new array every time I click Submit? 如何在每次加载页面时运行jQuery,甚至是从缓存中运行? - How do I get my jQuery to be run every time a page is loaded, even from the cache? 我如何找出为什么我的Javascript无法在IE中使用 - How do I find out why my Javascript is not working in IE 每次我尝试从不同的模块运行对象方法时,我都会收到“TypeError:Movie.getMovieList 不是函数” - Iam getting "TypeError: Movie.getMovieList is not a function" every time i try to run a object method from a different module 我如何禁用/启用提交按钮 - How do i disabled/enabled submit button 为什么每次运行函数时if语句都与else交替出现 - why my if statement alternates with else every time i run the function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM