maybe you can help me with my problem I tried to fix for hours. I have a function that should copy some values of cells of a row, if in column 6 of the row the value is being set to 6, to another spreadsheet. I already used ui.alert() to know where the function stops to work and it's when I overwrite the variable ss = SpreadsheetApp.getActiveSpreadsheet() with ss = SpreadsheetApp.openById('123456789'). I already made this in another Google Script and there it worked! Here you can see my Code:
var ui = SpreadsheetApp.getUi();
var ss = SpreadsheetApp.getActiveSpreadsheet();
function onOpen() {
ui.createMenu('xyz')
.addItem('xyz', 'menuItem1')
.addToUi();
}
function menuItem1() {
var row = SpreadsheetApp.getActiveSheet().getActiveCell().getRow();
var col = 2;
var x = SpreadsheetApp.getActiveSheet().getRange(row, col).getValue();
var y = Browser.inputBox(titletranslation , 'Please enter the translation here', Browser.Buttons.OK_CANCEL);
if(y != "cancel" && y != "") {
var id ="123456789"
doc = DriveApp.getFileById(id).makeCopy(y)
doc.setSharing(DriveApp.Access.ANYONE_WITH_LINK,DriveApp.Permission.EDIT)
var url = doc.getUrl()
SpreadsheetApp.getActiveSheet().getRange(row, 5).setValue(url)
}
}
function onEdit(event){
var row = event.range.getRow()
var column = event.range.getColumn()
if(column == 6) {
if(ss.getActiveSheet().getRange(row, column).getValue() == 6) {
var x = ss.getActiveSheet().getRange(row, 1)
var y = ss.getActiveSheet().getRange(row, 2)
var z = ss.getActiveSheet().getRange(row, 3)
var xx = ss.getName()
var yy = ss.getActiveSheet().getRange(row,4)
ss = SpreadsheetApp.openById('123456')
ss.setActiveSheet(ss.getSheetByName('Need to be published'))
ss.getActiveSheet().getRange(ss.getActiveSheet().getLastRow() + 1,1).setValue(x)
ss.getActiveSheet().getRange(ss.getActiveSheet().getLastRow() + 1,2).setValue(y)
ss.getActiveSheet().getRange(ss.getActiveSheet().getLastRow() + 1,3).setValue(z)
ss.getActiveSheet().getRange(ss.getActiveSheet().getLastRow() + 1,4).setValue(xx)
ss.getActiveSheet().getRange(ss.getActiveSheet().getLastRow() + 1,5).setValue(yy)
}
}
}
Hope you know what the problem is :) Thanks in advance
*active*
calls using scripts that are not container bound. Read this. In addition read minimal reproducible example, specifically, Describe the problem. "It doesn't work" isn't descriptive enough to help people understand your problem. Instead, tell other readers what the expected behavior should be. Tell other readers what the exact wording of the error message is, and which line of code is producing it. Use a brief but descriptive summary of your problem as the title of your question – TheMasterss.getsheetbyname()
returnssheet
. You can directly call.getRange()
and other calls onsheet
without activating it. – TheMaster