Reputation: 19
Google sheets does not find the function replace. What is wrong in my code?
The error message is:
function uptimeCheck() {
var ss = SpreadsheetApp.openById("XXXX");
var sheet = ss.getSheetByName('Tabellenblatt1');
var uptime_string = sheet.getRange("E5").getValue();
var uptime_zahl = uptime_string.replace(",", ".");
//Utilities.sleep(1120000);//hier wird acht Minuten gewartet, Zeit in Millisekunden
var uptime_new_string = sheet.getRange("E5").getValue();
var uptime_new_zahl = uptime_new_string.replace(/,/g , ".");
if (uptime_zahl != uptime_new_zahl)
{
var emailAddress = 'XXX';
var subject = 'Der Bot läuft nicht';
var message = 'Die uptime hat sich nicht verändert';
MailApp.sendEmail(emailAddress, subject,message);
}
}
Upvotes: 2
Views: 123
Reputation: 10345
Problem
The error message clearly states that there is no replace()
method in object 1.3.... This means that the value passed to the uptime_string
is not of type string
(most likely it is of type number
in your case) which doesn't have the replace()
method.
Solution
Ensure that the value is a string with toString()
method (this only one of possible ways to ensure the value is a string
, e.g. you might want to treat Date
values differently, etc):
uptime_string = sheet.getRange("E5").getValue().toString();
Notes
uptime_new_string
as it might suffer from the same issue.Upvotes: 1