google-apps-script - 对象不允许添加或更改属性 - 可安装的编辑触发器
问题描述
我在以下函数的标题中收到错误。简而言之,该功能检查是否在特定月份中填写了客户促销文章的所有标题。如果是这样 - 此客户 + 特定月份的主表中的订单状态更改为“是”。如果标题被删除 - 订单状态更改为空白。
如何更改代码以使其正常工作而不会出错?
谢谢!
function onEdit1(e) {
var range = e.range;
var column = range.getColumn();
var row = range.getRow();
var sheet = range.getSheet();
var cell = sheet.getActiveCell();
var spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
var masterSheet = spreadSheet.getSheetByName('Master');
var masterLastRow = masterSheet.getLastRow();
if(sheet == masterSheet) {
// in case user changed cell in the "Ordered articles?" column of a specific month in the master sheet
if ((column > 7) && (sheet.getRange(1,column).getValue() !== '')) {
// in case status marked as "Yes"
if (cell.getValue() == 'Yes') {
Browser.msgBox('In tab ' + sheet.getRange(1,column).getValue() + ': please verify that ' + sheet.getRange(row,3).getValue() + ' articles were submitted for the customer:' + sheet.getRange(row,1).getValue());
}
// in case existing status removed
else if (cell.isBlank()) {
Browser.msgBox('Cell cleared. Please verify that the info in tab ' + sheet.getRange(1,column).getValue() + ' matches this change, for the customer ' + sheet.getRange(row,1).getValue());
}
}
}
// in case user changed a cell of "article title" in a specific month sheet
else if ((sheet.getName() !== 'Inactive customers') && (column == 1) && (sheet.getRange(row,5).getValue = 'Promotion articles')) {
// in case added title is not added from top down for a specific customer (specified in column 2)
if ((sheet.getRange(row,2).getValue() == sheet.getRange(row - 1,2).getValue()) && (sheet.getRange(row - 1,column).isBlank())) {
Browser.msgBox('Please fill articles titles from top downwareds!');
cell.setValue('');
}
// in any other case
else {
var masterColumn;
// for loop finds the customer row in master sheet
for (var masterRow = 2; masterRow <= masterLastRow; masterRow++) {
// in case added title in specific month sheet is for the same customer in current row in master sheet
if (masterSheet.getRange(masterRow,2).getValue() == sheet.getRange(row,2).getValue()) {
masterColumn = 8;
// while loop finds the column for the specific month in master sheet
while (masterSheet.getRange(1,masterColumn).getValue() !== sheet.getName()) {
masterColumn++;
}
// in case title was erased, not added - status for "Ordered articles?" of specific month is cleared from master sheet
if (cell.isBlank()) {
masterSheet.getRange(masterRow,masterColumn).setValue('');
}
// in case title was added to the last row of a customer in specific month sheet - status is changed to "Yes" in master sheet
else if (sheet.getRange(row,2).getValue() !== sheet.getRange(row + 1,2).getValue()) {
masterSheet.getRange(masterRow,masterColumn).setValue('Yes');
}
// force end of for loop, after action was done
masterRow = masterLastRow;
}
}
}
}
}
解决方案
在“非活动客户”表的条件中,您有错字sheet.getRange(row,5).getValue = 'Promotion articles'
。那应该是.getValue() == 'Promotion articles'
。
此外,如果您采用批处理操作,看起来您可能会提高此代码的性能。
推荐阅读
- php - Laravel hasMany 基于附加关系的条件
- node.js - 如何从 mongodb 获取最后 10 条消息?
- python - 如何将实例属性带入 @staticmethod
- reactjs - 如何使用 react-final-form 多屏幕正确验证表单值?
- google-api - 未捕获的类型错误:无法读取 null 的属性“signIn”(在 localhost 上运行代码时!)
- google-apps-script - 将焦点放在工作表的一部分上
- javascript - Google 登录 API 失败:网络错误
- php - 用户登录时,在 Laravel 8.x 中调用 null 上的成员函数 prepare()
- javascript - 如何在异步函数中的数组内插入对象?
- pdf - SwiftUI PDF Kit 未填充可用视图空间