[edit] i finally got someone to unlock the range for me but i still get the error below. any insights?
I'm writing a gs to send data to MailChimp over the API. I can't even test to see if the function is working properly because so many of the sheets have protected ranges. This is a shared google sheet with upwards 30 users in it, tied to a form, so that's why it's protected (with edit access for everyone). Is there a way for me to hack into the authorization without requiring the document owner to unlock all the protected ranges? There are several sheets and several protected ranges, otherwise this would be a simple task to just unlock for me. I also work remote so explaining this process to an absolutely non-technical document owner is proving rather difficult..
I assume this has to do with protected ranges, but maybe I'm wrong? This is my error:
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.
Here is the main part that is the blocker, I think:
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();
**It's also important to note that none of this script is writing over anything in the sheet, it should just be read-only (so not a conflict with why ranges are protected)
mailchimp function for reference:
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)
}