jimbogarner
Board Regular
- Joined
- Apr 22, 2010
- Messages
- 103
Hi,
I'm looking for a script that can automatically import an email I receive in my work gmail account on a daily basis into a google database. The file always comes in the same format/name and from the same email address. I need it to copy the CSV into a specific tab each day overwriting the past data (the CSV is a cumulative file).
I found the below online, however, being completely transparent, I have no idea what i'm really doing with scripts, therefore this was very much copied and pasted and then I attempted to update the emails etc for my specifics, however, it doesn't work
function importsearchresultsCSVFromGmail2() {
var threads = GmailApp.search("from:Analytics.Reports@xxxxxx.com");
var messages = threads[0].getMessages();
var message = messages[messages.length - 1];
var attachment = message.getAttachments()[0];
// Is the attachment a CSV file
attachment.setContentType('text/csv');
//attachment.setContentTypeFromExtension();
if (attachment.getContentType() === "text/csv") {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var sh0 = sheet.getSheetByName("Daily_analytics")
var csvData = Utilities.parseCsv(attachment.getDataAsString(), ",");
// Remember to clear the content of the sheet before importing new data
sh0.getRange(3, 1, csvData.length, csvData[0].length).setValues(csvData);
GmailApp.markMessageRead(message);
}
This is the error i'm getting;
Thanks,
James
I'm looking for a script that can automatically import an email I receive in my work gmail account on a daily basis into a google database. The file always comes in the same format/name and from the same email address. I need it to copy the CSV into a specific tab each day overwriting the past data (the CSV is a cumulative file).
I found the below online, however, being completely transparent, I have no idea what i'm really doing with scripts, therefore this was very much copied and pasted and then I attempted to update the emails etc for my specifics, however, it doesn't work
function importsearchresultsCSVFromGmail2() {
var threads = GmailApp.search("from:Analytics.Reports@xxxxxx.com");
var messages = threads[0].getMessages();
var message = messages[messages.length - 1];
var attachment = message.getAttachments()[0];
// Is the attachment a CSV file
attachment.setContentType('text/csv');
//attachment.setContentTypeFromExtension();
if (attachment.getContentType() === "text/csv") {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var sh0 = sheet.getSheetByName("Daily_analytics")
var csvData = Utilities.parseCsv(attachment.getDataAsString(), ",");
// Remember to clear the content of the sheet before importing new data
sh0.getRange(3, 1, csvData.length, csvData[0].length).setValues(csvData);
GmailApp.markMessageRead(message);
}
This is the error i'm getting;
Thanks,
James