All of a sudden getting an error in Google Sheets from this function that existed for years. Did they change...
up vote
0
down vote
favorite
I wrote a function a while ago to determine if a sheet in a workbook already exists. Here is the function:
function SheetNameExists(name){
return (ActiveSpreadSheet().getSheetByName(name).toString().indexOf(name) != 0);
}
All of a sudden within the last month or so I get a TypeError: Cannot call method "toString" of null. (line 105, file "Code")
. Line 105 is the return
statement.
Up until this error started happening I have had no issues with any of the scripts on this Sheet. I did not change anything in the code-behind.
Did Google change up something without providing deprecation support?
EDIT: I forgot ActiveSpreadsheet()
was not a built-in function when I wrote all this out. This is the code I wrote to get it:
function ActiveSpreadSheet(){
return SpreadsheetApp.getActiveSpreadsheet();
}
google-apps-script
add a comment |
up vote
0
down vote
favorite
I wrote a function a while ago to determine if a sheet in a workbook already exists. Here is the function:
function SheetNameExists(name){
return (ActiveSpreadSheet().getSheetByName(name).toString().indexOf(name) != 0);
}
All of a sudden within the last month or so I get a TypeError: Cannot call method "toString" of null. (line 105, file "Code")
. Line 105 is the return
statement.
Up until this error started happening I have had no issues with any of the scripts on this Sheet. I did not change anything in the code-behind.
Did Google change up something without providing deprecation support?
EDIT: I forgot ActiveSpreadsheet()
was not a built-in function when I wrote all this out. This is the code I wrote to get it:
function ActiveSpreadSheet(){
return SpreadsheetApp.getActiveSpreadsheet();
}
google-apps-script
I think that the error indicates thatActiveSpreadSheet().getSheetByName(name)
returnsnull
. So please confirm whether there is the sheet name ofname
in the Spreadsheet, again. And in your case,ActiveSpreadSheet().getSheetByName(name).toString()
returnsSheet
for various values ofname
. So I think that atActiveSpreadSheet().getSheetByName(name).toString().indexOf(name) != 0
, only whenname
isSheet
, it becomesfalse
.
– Tanaike
Nov 13 at 3:20
I've used this sheet and the functions flawlessly for almost 4 years now. I can post the full code-behind if necessary.
– Anders
Nov 13 at 3:22
2
Thank you for replying. For example, how about creating new spreadsheet and copying the values, sheets and the script, and then, running the script? If that was not the solution, in order to confirm your situation, can you provide a sample spreadsheet including the script for replicating your issue? Of course, please remove your private information.
– Tanaike
Nov 13 at 8:06
There are probably only a few of reasons whySpreadsheetApp.getActiveSpreadsheet()
would fail. 1) The code is being run many times in rapid succession, and a quota limit is being hit 2) The script project is not bound to a Sheet 3) Google servers had a service outage. 4) Maybe the permissions changed?SpreadsheetApp.getActiveSpreadsheet()
is used a lot. If there was a service outage on Google's servers, there would be at least thousands of people complaining that their code didn't work any more. Does anyone else have access to the Sheet? Have you removed an permissions recently?
– Sandy Good
Nov 13 at 13:45
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I wrote a function a while ago to determine if a sheet in a workbook already exists. Here is the function:
function SheetNameExists(name){
return (ActiveSpreadSheet().getSheetByName(name).toString().indexOf(name) != 0);
}
All of a sudden within the last month or so I get a TypeError: Cannot call method "toString" of null. (line 105, file "Code")
. Line 105 is the return
statement.
Up until this error started happening I have had no issues with any of the scripts on this Sheet. I did not change anything in the code-behind.
Did Google change up something without providing deprecation support?
EDIT: I forgot ActiveSpreadsheet()
was not a built-in function when I wrote all this out. This is the code I wrote to get it:
function ActiveSpreadSheet(){
return SpreadsheetApp.getActiveSpreadsheet();
}
google-apps-script
I wrote a function a while ago to determine if a sheet in a workbook already exists. Here is the function:
function SheetNameExists(name){
return (ActiveSpreadSheet().getSheetByName(name).toString().indexOf(name) != 0);
}
All of a sudden within the last month or so I get a TypeError: Cannot call method "toString" of null. (line 105, file "Code")
. Line 105 is the return
statement.
Up until this error started happening I have had no issues with any of the scripts on this Sheet. I did not change anything in the code-behind.
Did Google change up something without providing deprecation support?
EDIT: I forgot ActiveSpreadsheet()
was not a built-in function when I wrote all this out. This is the code I wrote to get it:
function ActiveSpreadSheet(){
return SpreadsheetApp.getActiveSpreadsheet();
}
google-apps-script
google-apps-script
edited Nov 13 at 3:17
asked Nov 13 at 2:59
Anders
5,1423083132
5,1423083132
I think that the error indicates thatActiveSpreadSheet().getSheetByName(name)
returnsnull
. So please confirm whether there is the sheet name ofname
in the Spreadsheet, again. And in your case,ActiveSpreadSheet().getSheetByName(name).toString()
returnsSheet
for various values ofname
. So I think that atActiveSpreadSheet().getSheetByName(name).toString().indexOf(name) != 0
, only whenname
isSheet
, it becomesfalse
.
– Tanaike
Nov 13 at 3:20
I've used this sheet and the functions flawlessly for almost 4 years now. I can post the full code-behind if necessary.
– Anders
Nov 13 at 3:22
2
Thank you for replying. For example, how about creating new spreadsheet and copying the values, sheets and the script, and then, running the script? If that was not the solution, in order to confirm your situation, can you provide a sample spreadsheet including the script for replicating your issue? Of course, please remove your private information.
– Tanaike
Nov 13 at 8:06
There are probably only a few of reasons whySpreadsheetApp.getActiveSpreadsheet()
would fail. 1) The code is being run many times in rapid succession, and a quota limit is being hit 2) The script project is not bound to a Sheet 3) Google servers had a service outage. 4) Maybe the permissions changed?SpreadsheetApp.getActiveSpreadsheet()
is used a lot. If there was a service outage on Google's servers, there would be at least thousands of people complaining that their code didn't work any more. Does anyone else have access to the Sheet? Have you removed an permissions recently?
– Sandy Good
Nov 13 at 13:45
add a comment |
I think that the error indicates thatActiveSpreadSheet().getSheetByName(name)
returnsnull
. So please confirm whether there is the sheet name ofname
in the Spreadsheet, again. And in your case,ActiveSpreadSheet().getSheetByName(name).toString()
returnsSheet
for various values ofname
. So I think that atActiveSpreadSheet().getSheetByName(name).toString().indexOf(name) != 0
, only whenname
isSheet
, it becomesfalse
.
– Tanaike
Nov 13 at 3:20
I've used this sheet and the functions flawlessly for almost 4 years now. I can post the full code-behind if necessary.
– Anders
Nov 13 at 3:22
2
Thank you for replying. For example, how about creating new spreadsheet and copying the values, sheets and the script, and then, running the script? If that was not the solution, in order to confirm your situation, can you provide a sample spreadsheet including the script for replicating your issue? Of course, please remove your private information.
– Tanaike
Nov 13 at 8:06
There are probably only a few of reasons whySpreadsheetApp.getActiveSpreadsheet()
would fail. 1) The code is being run many times in rapid succession, and a quota limit is being hit 2) The script project is not bound to a Sheet 3) Google servers had a service outage. 4) Maybe the permissions changed?SpreadsheetApp.getActiveSpreadsheet()
is used a lot. If there was a service outage on Google's servers, there would be at least thousands of people complaining that their code didn't work any more. Does anyone else have access to the Sheet? Have you removed an permissions recently?
– Sandy Good
Nov 13 at 13:45
I think that the error indicates that
ActiveSpreadSheet().getSheetByName(name)
returns null
. So please confirm whether there is the sheet name of name
in the Spreadsheet, again. And in your case, ActiveSpreadSheet().getSheetByName(name).toString()
returns Sheet
for various values of name
. So I think that at ActiveSpreadSheet().getSheetByName(name).toString().indexOf(name) != 0
, only when name
is Sheet
, it becomes false
.– Tanaike
Nov 13 at 3:20
I think that the error indicates that
ActiveSpreadSheet().getSheetByName(name)
returns null
. So please confirm whether there is the sheet name of name
in the Spreadsheet, again. And in your case, ActiveSpreadSheet().getSheetByName(name).toString()
returns Sheet
for various values of name
. So I think that at ActiveSpreadSheet().getSheetByName(name).toString().indexOf(name) != 0
, only when name
is Sheet
, it becomes false
.– Tanaike
Nov 13 at 3:20
I've used this sheet and the functions flawlessly for almost 4 years now. I can post the full code-behind if necessary.
– Anders
Nov 13 at 3:22
I've used this sheet and the functions flawlessly for almost 4 years now. I can post the full code-behind if necessary.
– Anders
Nov 13 at 3:22
2
2
Thank you for replying. For example, how about creating new spreadsheet and copying the values, sheets and the script, and then, running the script? If that was not the solution, in order to confirm your situation, can you provide a sample spreadsheet including the script for replicating your issue? Of course, please remove your private information.
– Tanaike
Nov 13 at 8:06
Thank you for replying. For example, how about creating new spreadsheet and copying the values, sheets and the script, and then, running the script? If that was not the solution, in order to confirm your situation, can you provide a sample spreadsheet including the script for replicating your issue? Of course, please remove your private information.
– Tanaike
Nov 13 at 8:06
There are probably only a few of reasons why
SpreadsheetApp.getActiveSpreadsheet()
would fail. 1) The code is being run many times in rapid succession, and a quota limit is being hit 2) The script project is not bound to a Sheet 3) Google servers had a service outage. 4) Maybe the permissions changed? SpreadsheetApp.getActiveSpreadsheet()
is used a lot. If there was a service outage on Google's servers, there would be at least thousands of people complaining that their code didn't work any more. Does anyone else have access to the Sheet? Have you removed an permissions recently?– Sandy Good
Nov 13 at 13:45
There are probably only a few of reasons why
SpreadsheetApp.getActiveSpreadsheet()
would fail. 1) The code is being run many times in rapid succession, and a quota limit is being hit 2) The script project is not bound to a Sheet 3) Google servers had a service outage. 4) Maybe the permissions changed? SpreadsheetApp.getActiveSpreadsheet()
is used a lot. If there was a service outage on Google's servers, there would be at least thousands of people complaining that their code didn't work any more. Does anyone else have access to the Sheet? Have you removed an permissions recently?– Sandy Good
Nov 13 at 13:45
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I question how this could have worked before. getSheetByName(name) will return a Sheet object. toString() simply returns the string "Sheet". So it will only match name if name is "Sheet". However your problem is quite simple.
var active = SpreadsheetApp.getActiveSpreadsheet(); // For sure the active spreadsheet
var sheet = active.getSheetByName(name); // Where name is a string representing a sheet name
if( sheet ) return true; // Sheet with name exists
return false; // Other wise sheet is null or does not exist
Thank you this worked! I changed the function that was getting an error to the following:function SheetNameExists(name){ return ActiveSheetByName(name); }
. TheActiveSheetByName()
function just does what your second line does. Thanks again!
– Anders
56 mins ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I question how this could have worked before. getSheetByName(name) will return a Sheet object. toString() simply returns the string "Sheet". So it will only match name if name is "Sheet". However your problem is quite simple.
var active = SpreadsheetApp.getActiveSpreadsheet(); // For sure the active spreadsheet
var sheet = active.getSheetByName(name); // Where name is a string representing a sheet name
if( sheet ) return true; // Sheet with name exists
return false; // Other wise sheet is null or does not exist
Thank you this worked! I changed the function that was getting an error to the following:function SheetNameExists(name){ return ActiveSheetByName(name); }
. TheActiveSheetByName()
function just does what your second line does. Thanks again!
– Anders
56 mins ago
add a comment |
up vote
1
down vote
accepted
I question how this could have worked before. getSheetByName(name) will return a Sheet object. toString() simply returns the string "Sheet". So it will only match name if name is "Sheet". However your problem is quite simple.
var active = SpreadsheetApp.getActiveSpreadsheet(); // For sure the active spreadsheet
var sheet = active.getSheetByName(name); // Where name is a string representing a sheet name
if( sheet ) return true; // Sheet with name exists
return false; // Other wise sheet is null or does not exist
Thank you this worked! I changed the function that was getting an error to the following:function SheetNameExists(name){ return ActiveSheetByName(name); }
. TheActiveSheetByName()
function just does what your second line does. Thanks again!
– Anders
56 mins ago
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I question how this could have worked before. getSheetByName(name) will return a Sheet object. toString() simply returns the string "Sheet". So it will only match name if name is "Sheet". However your problem is quite simple.
var active = SpreadsheetApp.getActiveSpreadsheet(); // For sure the active spreadsheet
var sheet = active.getSheetByName(name); // Where name is a string representing a sheet name
if( sheet ) return true; // Sheet with name exists
return false; // Other wise sheet is null or does not exist
I question how this could have worked before. getSheetByName(name) will return a Sheet object. toString() simply returns the string "Sheet". So it will only match name if name is "Sheet". However your problem is quite simple.
var active = SpreadsheetApp.getActiveSpreadsheet(); // For sure the active spreadsheet
var sheet = active.getSheetByName(name); // Where name is a string representing a sheet name
if( sheet ) return true; // Sheet with name exists
return false; // Other wise sheet is null or does not exist
answered Nov 13 at 15:46
TheWizEd
41147
41147
Thank you this worked! I changed the function that was getting an error to the following:function SheetNameExists(name){ return ActiveSheetByName(name); }
. TheActiveSheetByName()
function just does what your second line does. Thanks again!
– Anders
56 mins ago
add a comment |
Thank you this worked! I changed the function that was getting an error to the following:function SheetNameExists(name){ return ActiveSheetByName(name); }
. TheActiveSheetByName()
function just does what your second line does. Thanks again!
– Anders
56 mins ago
Thank you this worked! I changed the function that was getting an error to the following:
function SheetNameExists(name){ return ActiveSheetByName(name); }
. The ActiveSheetByName()
function just does what your second line does. Thanks again!– Anders
56 mins ago
Thank you this worked! I changed the function that was getting an error to the following:
function SheetNameExists(name){ return ActiveSheetByName(name); }
. The ActiveSheetByName()
function just does what your second line does. Thanks again!– Anders
56 mins ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273153%2fall-of-a-sudden-getting-an-error-in-google-sheets-from-this-function-that-existe%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think that the error indicates that
ActiveSpreadSheet().getSheetByName(name)
returnsnull
. So please confirm whether there is the sheet name ofname
in the Spreadsheet, again. And in your case,ActiveSpreadSheet().getSheetByName(name).toString()
returnsSheet
for various values ofname
. So I think that atActiveSpreadSheet().getSheetByName(name).toString().indexOf(name) != 0
, only whenname
isSheet
, it becomesfalse
.– Tanaike
Nov 13 at 3:20
I've used this sheet and the functions flawlessly for almost 4 years now. I can post the full code-behind if necessary.
– Anders
Nov 13 at 3:22
2
Thank you for replying. For example, how about creating new spreadsheet and copying the values, sheets and the script, and then, running the script? If that was not the solution, in order to confirm your situation, can you provide a sample spreadsheet including the script for replicating your issue? Of course, please remove your private information.
– Tanaike
Nov 13 at 8:06
There are probably only a few of reasons why
SpreadsheetApp.getActiveSpreadsheet()
would fail. 1) The code is being run many times in rapid succession, and a quota limit is being hit 2) The script project is not bound to a Sheet 3) Google servers had a service outage. 4) Maybe the permissions changed?SpreadsheetApp.getActiveSpreadsheet()
is used a lot. If there was a service outage on Google's servers, there would be at least thousands of people complaining that their code didn't work any more. Does anyone else have access to the Sheet? Have you removed an permissions recently?– Sandy Good
Nov 13 at 13:45