onEdit简单触发器似乎从未被触发 [英] onEdit simple trigger never seems to be triggered

查看:58
本文介绍了onEdit简单触发器似乎从未被触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在使用 OnEdit ,并且效果很好-但是现在我遇到了一个问题-基本上在编辑第6(f)栏时希望它检查值-如果它是 In Progress,则我希望它运行一个函数以发送电子邮件,当我调试它时-它的工作原理与我想要的完全一样,但是当我不调试时,它似乎从未出现过

I've been using OnEdit for some time and its been working great - however just now ive came accross a problem - basically when column 6 (f) is edited I want it to check the value - if it is "In Progress" I want it to then run a function to send an email, when I debug this - it works great exactly as I want it to, however when im not debugging it never seems to run.

var summary = ss.getSheetByName("Summary")
var data = summary.getRange(4, 1, summary.getLastRow(), summary.getLastColumn());
var learnerObjects = getRowsData(summary, data);
var lastrow = summary.getLastRow();

function onEdit(e){
  var sheet = e.source.getActiveSheet();
  var CellRow = sheet.getActiveRange().getRow();
  var CellColumn = sheet.getActiveRange().getColumn();

  if (sheet.getSheetName() == "Summary"){
    if (CellColumn == 6){
      var learner = learnerObjects[CellRow-4];
      var status = learner.status;
      if (status == "In Progress"){
        var enrolmentdate = learner.enrolmentDateDdmmyyyy;
        var surname = learner.surname;
        var firstname = learner.firstName;
        var qualification = learner.qualification;
        var company = learner.company;
        messagePT3 = firstname + " " + surname + " from " + company + " doing " + qualification + " has been added to your tracker.";
        sendTrackerEmail(messagePT3);
        SpreadsheetApp.getActiveSpreadsheet().toast('Email has been sent to Assessor regarding new learner', 'Assessor Notified', 3);
      }
    }
  }
}

此是它的主要代码,在调试时如我所说的那样可以很好地工作,但是当我不调试时,它似乎从未被触发,我还有其他方法可以这样做吗?

This is the main code for it, when debugging as I say it works fine, however when im not debugging it never seems to be triggered, is there any other ways for me to do this?

我在F列上进行了数据验证,但是这将单元格限制为已完成,已撤回,已暂停或进行中-应该不会起作用吗?

I have data validation on column F however this limits the cells to "Completed", "Withdrawn", "Suspended" or "In Progress" - this shouldnt have an effect should it?

我知道 onEdit 被触发,因为我使用它来监视电子表格的某些部分的更改。

I know that onEdit is being triggered as I use it for monitoring changes to certain parts of the spreadsheet.

推荐答案

onEdit()触发器是所谓的简单触发器,其作用域有限。
由于它在活动用户的权限下自动且安静地运行,因此它无法执行任何需要授权的操作,例如,它无法发送电子邮件!

The onEdit() trigger is a so called "simple trigger" that has a limited field of action. Since it runs automatically and silently under the authority of the active user it can't do anything that requires authorization, for example it can't send emails !

解决方案很简单:将函数名称更改为其他名称(例如,myOnEdit)并设置一个可安装的onEdit触发器以运行该函数。(菜单资源/当前脚本触发器/在脚本编辑器中创建新触发器。)

The solution is simple : change your function name to something else (myOnEdit for example) and set an installable onEdit trigger to run that function.(menu ressource/current script trigger/create new trigger in the script editor.)

这一次,当有人编辑电子表格时,它将在您执行时(您将发送电子邮件)。

This time it will be executed as you (you'll be sending the emails) when anyone edits the spreadsheet.

文档在此处可用

这篇关于onEdit简单触发器似乎从未被触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆