【发布时间】:2018-04-16 08:34:51
【问题描述】:
[edit] 我终于有人帮我解锁了范围,但我仍然收到以下错误。有什么见解吗?
我正在编写一个 gs 以通过 API 将数据发送到 MailChimp。我什至无法测试该功能是否正常工作,因为很多工作表都有受保护的范围。这是一个共享的 google 表格,其中有超过 30 个用户,绑定到一个表单,所以这就是它受到保护的原因(每个人都有编辑权限)。有没有办法让我在不要求文档所有者解锁所有受保护范围的情况下侵入授权?有几张纸和几个受保护的范围,否则这对我来说将是一项简单的解锁任务。我也在远程工作,所以向一个完全非技术性的文档所有者解释这个过程是相当困难的..
我认为这与受保护的范围有关,但也许我错了?这是我的错误:
Method ScriptApp.newTrigger invoked in the global scope.Collapse
File: Attendance Email Line: 95
This function invocation will fail when the script is run as an Add-on in AuthMode.NONE.
这里是拦截器的主要部分,我认为:
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var attendance = ss.getSheetByName("ATTENDANCE");
attendance.activate();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var currentSelection = SpreadsheetApp.getActiveSheet().getActiveSelection()
var currentRow = currentSelection.getRowIndex();
Logger.log(currentRow);
Logger.log(currentSelection);
return currentRow;
return currentSelection;
var email = e.currentSelection[currentRow,2,1,1];
var lead = e.currentSelection[currentRow,1,1,1];
var latecount = e.currentSelection[currentRow,6,1,1];
var calloffcnt = e.currentSelection[currentRow,7,1,1];
var wfhcnt = e.currentSelection[currentRow,8,1,1];
var wfhoccur = e.currentSelection[currentRow,9,1,1];
var wfhremain = e.currentSelection[currentRow,10,1,1];
var anncalloff = e.currentSelection[currentRow,11,1,1];
var occurtotal = e.currentSelection[currentRow,21,1,1];
var usedpto = e.currentSelection[currentRow,22,1,1];
var usedsick = e.currentSelection[currentRow,23,1,1];
var ptoremain = e.currentSelection[currentRow,24,1,1];
var sickremain = e.currentSelection[currentRow,25,1,1];
sendToMailChimp_(email,lead,latecount,calloffcnt,wfhcnt,wfhoccur,wfhremain,anncalloff,occurtotal,usedpto,usedsick,ptoremain,sickremain);
}
/**
* Main function. Creates onEdit trigger.
*/
function myFunction (){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var attendance = ss.getSheetByName("ATTENDANCE");
attendance.activate();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
}
ScriptApp.newTrigger("myFunction")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onEdit()
.create();
**同样重要的是要注意,此脚本中的任何内容都不会覆盖工作表中的任何内容,它应该只是只读的(因此与保护范围的原因不冲突)
mailchimp函数供参考:
function sendToMailChimp_(email,lead,latecount,calloffcnt,wfhcnt,wfhoccur,wfhremain,anncalloff,occurtotal,usedpto,usedsick,ptoremain,sickremain){
var payload = {
"apikey": API_KEY,
"id": LIST_ID,
"merge_fields[EMAIL]": email,
"merge_fields[LEAD]": lead,
"merge_fields[LATECOUNT]": latecount,
"merge_fields[CALLOFFCNT]": calloffcnt,
"merge_fields[WFHCNT]": wfhcnt,
"merge_fields[WFHOCCUR]": wfhoccur,
"merge_fields[WFHREMAIN]": wfhremain,
"merge_fields[ANNCALLOFF]": anncalloff,
"merge_fields[OCCURTOTAL]": occurtotal,
"merge_fields[USEDPTO]": usedpto,
"merge_fields[USEDSICK]": usedsick,
"merge_fields[PTOREMAIN]": ptoremain,
"merge_fields[SICKREMAIN]": sickremain,
"double_optin": mc_double_optin,
"update_existing": true
};
var payload = JSON.stringify;
var options = {
"method": "patch",
"payload" : JSON.stringify(payload)
};
var response = UrlFetchApp.fetch(mc_base_url,options);
Logger.log(response)
}
【问题讨论】:
-
我认为工作表或范围没有名为 getActiveSelection() 的方法。此外,如果您已经有一个名为 onEdit() 的函数,则无需创建可安装的 onEdit 函数
-
谢谢!我确实从其他人的成功脚本或应用程序站点本身获得了 getActiveSelection,但我可能缺少与之相关的功能?在这种情况下,您建议我如何获取参考特定列的更新单元格?
-
正在编辑的工作表名称是“ATTENDANCE”吗?
-
是的!基本上我需要一种方法来获取与特定行相对应的更新单元格和与 mailchimp 中的数据匹配的列(在这种情况下,统一数据块是电子邮件)
-
试试我的答案,看看它是否适合你。
标签: javascript json google-apps-script google-sheets-api mailchimp-api-v3.0