How can I solve permission problems with custom functions (calling from Google sheet cells)?
Like
- "You do not have permission to call setDataValidation"
- "You do not have permission to call setValue"
I researched a lot on these types of the issue especially checked similar issues on Stack Overflow. Some say to add scopes in projects properties(my project already has required scope), some say to call a custom function from menu or buttons.
But my requirement is to call the custom function from Google Sheets from a cell.
I will then share that sheet with my organization (GSuite), so they can have access to the data and custom functions.
I am in trouble, I did not find any solution.
Please suggest possible ways to correct this problem.
*I can easily call these function from Google Apps Script directly (from run) but not from sheets.
Sample code that throws error "You do not have permission to call setDataValidation"
function getNamedRanges(type,cell){ // parms ex. ("Cars" ,"D1")
Logger.log(type);
var namedRanges = SpreadsheetApp.getActive().getNamedRanges();
for (var i = 0; i < namedRanges.length; i++) {
if(namedRanges[i].getName()==type){
var cell = SpreadsheetApp.getActive().getRange(cell)
createDropdownForRange(namedRanges[i].getRange(),cell);
}
}
}
function createDropdownForRange(namedRange,cell){
var rule = SpreadsheetApp
.newDataValidation()
.requireValueInRange(namedRange,true);
cell.setDataValidation(rule);
}