I'm facing a little problem. I'm using google sheet and google appscript to send email to customers. However when I use the same code on two different sheets the date format in the mail title changes.
One will give me
Facture Osteo n° 14752 du 27/06/2022
and the other (the wrong one)
Facture Osteo n°14752 du Mon Jun 27 2022 00:00:00 GMT 0200 (heure d’été d’Europe centrale)
To create the email I use data from a sheet and it replace data in an another sheet used to generate the invoice.
I checked the settings in the google sheet I don't see any issue with it, same timezone and country.
Anyone one as an idea?
function Facturereview2() {
var app = SpreadsheetApp;
var data=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getDataRange().getValues();
var currRow = SpreadsheetApp.getActiveSheet().getActiveCell().getRow();
var i=currRow-1
var donneesFacture=data[i];
var doc=app.openById("1zGzIrT8AT0rGRfYR-qIOYJt-lB_IGLvSyh3BWPjKlxU")
var Facture = doc.getSheetByName("Facture");
Facture.getRange(2,4).setValue(donneesFacture[1]);
Facture.getRange(11,4).setValue(donneesFacture[2]);
Facture.getRange(13,5).setValue(donneesFacture[0]);
Facture.getRange(19,7).setValue(donneesFacture[3]);
SpreadsheetApp.flush();
var pdf=doc.getAs('application/pdf');
var file=DriveApp.createFile(pdf);
DriveApp.removeFile(DriveApp.getFileById(doc.getId()));
const HTMLTemplate = HtmlService.createTemplateFromFile("Facture review")
const HTMLforemail = HTMLTemplate.evaluate().getContent()
var email=donneesFacture[9]
var sujet="Facture Osteo n°" donneesFacture[1] " du " donneesFacture[2]; // donneesFacture[2] is the date
var texte="Veuillez trouver ci attachée votre note d'honoraire du " donneesFacture[2] ".\nText,\n\n Text";
var option={
htmlBody:HTMLforemail,
attachments:file
};
GmailApp.sendEmail(email,sujet,texte, option);
}
CodePudding user response:
Replace .getValues()
with .getDisplayValues()
to get all data, including dates, as text strings in the format they show in the spreadsheet.