gpt4 book ai didi

javascript - Google Apps 脚本功能在我手动运行时执行,但在作为触发器运行时失败,引用错误代码 INTERNAL

转载 作者:行者123 更新时间:2023-12-03 18:32:01 24 4
gpt4 key购买 nike

关闭。这个问题需要更多 focused .它目前不接受答案。












想改进这个问题?更新问题,使其仅关注一个问题 editing this post .


去年关闭。







Improve this question




我有一个链接到 Google 表格的 Google 表单。在 Google 表格中,我有一个 Google Apps 脚本函数,它将输入与 Google 表单分开并逐行存储每个项目。我有一个 VLookup 设置,可以根据 Google Apps 脚本的解析从另一个电子表格中提取信息。提取信息后,我会将信息通过电子邮件发送到通过 Google 表单提供的电子邮件。我有一个触发器设置,可以在提交表单时自动运行该功能。下图是表格中的表格结果。
Form submission information
当我在 Google 表单上选择一些选项时,触发器会起作用。一旦我选择更多选项,大约 20+,它会返回以下错误代码:

We're sorry, the JavaScript engine reported an unexpected error. Error code INTERNAL.


但是,当我手动运行该功能时,它可以完美执行。我不太确定问题是什么。我发现的与此问题有关的唯一其他问题是 Web App call fails with "... Error code INTERNAL" with Custom API ,但我已经在使用 openByID。下面函数 onFormSubmit 中的 e 是我尝试使用表单对象,但我还没有让它工作。我不相信这会导致问题。
//Object to store city & state in one object
function city (city, state) {
this.city = city;
this.state = state;
}

function onFormSubmit (e) {
// Set active sheet and store form information in variables
//This function runs based off a formSubmit trigger
var sheet = SpreadsheetApp.openById('sampleID');
SpreadsheetApp.setActiveSheet(sheet.getSheets()[0]);
var lastRow = String(sheet.getLastRow());
var email = String(sheet.getRange('D' +lastRow).getValue());
var name = String(sheet.getRange('B' + lastRow).getValue());
var company = String(sheet.getRange('C' + lastRow).getValue());
var state = String(sheet.getRange('E' + lastRow).getValue()).split(",");
var list_cities = [];

//Separates City, State into object with City & State properties
n = 0
for (x of String(sheet.getRange('F' + lastRow).getValue()).split(",")) {
if (n == 0) {
var city_name = x.trim();
n = 1;
}
else {
n = 0;
var temp = new city(city_name, x.trim());
list_cities.push(temp);
}
}

//Moves to next sheet
SpreadsheetApp.setActiveSheet(sheet.getSheets()[1]);

//Clear Form tab
lastRow = String(SpreadsheetApp.getActive().getLastRow());
SpreadsheetApp.getActiveSheet().getRangeList(['A2:B2', 'A3:F' + lastRow]).clear();

// Initializes first row
var row = 2;

//Fills in State column
for (x of state) {
SpreadsheetApp.getActiveSheet().getRange(row, 1).setValue(x.trim());
row = row + 1;
}

//Fills in City column
for (x of list_cities) {
SpreadsheetApp.getActiveSheet().getRange(row,1).setValue(x.state);
SpreadsheetApp.getActiveSheet().getRange(row, 2).setValue(x.city);
row = row + 1
}

//List of cell column headers
var letters = ["C", "D", "E", "F"];

//Copies down formula for each column
for (x of letters) {
var sourceRange = SpreadsheetApp.getActiveSheet().getRange(x + String(2));
var destination = SpreadsheetApp.getActiveSheet().getRange(x + String(2) + ":" + x + String(row-1));
sourceRange.autoFill(destination, SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
}

SpreadsheetApp.flush();

//Extracts only completed sheet
var url = "https://docs.google.com/";
var params = {
method : "get",
headers : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
muteHttpExceptions: true
};
var blob = UrlFetchApp.fetch(url, params).getBlob();
blob.setName(SpreadsheetApp.getActive().getName() + ".xlsx");

//Set email information and send email
var message = {
to: email,
name: 'Name',
subject: company + " Subject",
body: "Body text",
attachments: blob
}
MailApp.sendEmail(message)
}

最佳答案

看起来这是 v8 引擎中的一个问题,现在正在调查:
https://issuetracker.google.com/issues/184759540
同时要解决这个问题,将你的代码从运行时 V8 切换到 DEPRECATED_ES5 应该可以解决这个问题。
除了错误,您正在通过 onFormSubmit 参数传递事件对象,但不使用它。
例子:

function onFormSubmit(e) {
let response = e.namedValues;

var email = response['Email:'];
var name = response['Name:'];
var company = response['Company:'];
var state = response['State:'];

//Remaining code below!
}
获取命名值会返回一个对象,其中键是 Google 表单中的问题,值是表单提交中的答案。

关于javascript - Google Apps 脚本功能在我手动运行时执行,但在作为触发器运行时失败,引用错误代码 INTERNAL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66995465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com