【问题标题】:Run trigger by LastRow通过 LastRow 运行触发器
【发布时间】:2022-07-23 02:34:09
【问题描述】:

我已经花了几天时间试图弄清楚如何编写我需要的脚本。这是我目前拥有的

function setUpTrigger(){

ScriptApp.newTrigger('LOOKUP')
.forForm('11jqQgzXiCT0XH8fAlfFS8y3_XgdY69L5QfoHAFwW0rk')
.onFormSubmit()
.create();

}

function LOOKUP() {
const ss = SpreadsheetApp.getActiveSpreadsheet()
const wsLogsheet = ss.getSheetByName ("Respondent Log")
const wsLimit = ss.getSheetByName("Limit")
const limitData=  wsLimit.getRange(2,1, wsLimit.getLastRow()-1,3).getValues()
const searchValue =  wsLogsheet .getRange("B2").getValue()
const matchRow = limitData .find(r => r[0] == searchValue)
const match = matchRow ? matchRow[2]: null
wsLogsheet.getRange("J2").setValue(match)

我想对其进行设置,使其在每次新提交时在每个 lastrow(J 列)上运行。每次触发之前的条目也将保持不变。这意味着如果我更改查找数据上的值,以前的条目将不会受到影响。

【问题讨论】:

    标签: google-apps-script google-sheets triggers google-forms


    【解决方案1】:

    试试这个方法:

    function LOOKUP(e) {
      const log = e.source.getSheetByName("Respondent Log")
      const lim = e.source.getSheetByName("Limit")
      const limvs = lim.getRange(2, 1, lim.getLastRow() - 1, 3).getValues()
      const searchValue = log.getRange("B2").getValue();
      const row = limvs.find(r => r[0] == searchValue)
      log.getRange("J2").setValue(row[2]);
    }
    function setUpTrigger() {
      ScriptApp.newTrigger('LOOKUP').forSpreadsheet(SpreadsheetApp.getActive()).onFormSubmit().create()
    }
    

    【讨论】:

    • 感谢您的回复。我收到一个错误 TypeError: Cannot read property 'source' of undefined。我还尝试将 lastrow 添加到我的 b2 和 j2 脚本中,但该列仍然为空白
    • 您无法从脚本编辑器运行此功能。它需要来自触发器的事件对象
    猜你喜欢
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-21
    • 2016-10-23
    • 1970-01-01
    • 2017-07-29
    相关资源
    最近更新 更多