[编辑]我终于有人为我解锁了范围,但我仍然得到以下错误。任何见解?
我正在写一个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)
}
答案 0 :(得分:0)
试试这个:
function onEdit()
{
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var rg=sh.getActiveRange()
if(sh.getName()=="ATTENDANCE")
{
var currentRow = rg.getRow();
var email = sh.getRange(currentRow,2).getValue();
var lead = sh.getRange(currentRow,1).getValue();
var latecount = sh.getRange(currentRow,6).getValue();
var calloffcnt = sh.getRange(currentRow,7).getValue();
var wfhcnt = sh.getRange(currentRow,8).getValue();
var wfhoccur = sh.getRange(currentRow,9).getValue();
var wfhremain = sh.getRange(currentRow,10).getValue();
var anncalloff = sh.getRange(currentRow,11).getValue();
var occurtotal = sh.getRange(currentRow,21).getValue();
var usedpto = sh.getRange(currentRow,22).getValue();
var usedsick = sh.getRange(currentRow,23).getValue();
var ptoremain = sh.getRange(currentRow,24).getValue();
var sickremain = sh.getRange(currentRow,25).getValue();
sendToMailChimp_(email,lead,latecount,calloffcnt,wfhcnt,wfhoccur,wfhremain,anncalloff,occurtotal,usedpto,usedsick,ptoremain,sickremain);
}
}