Home>
I am a beginner.
With reference to the following URL, we have created a system that extracts email forms into spreadsheets.
https://www.virment.com/google-apps-script-gmail-spreadsheet/
I made it according to the site, but the following error message occurred from the second email.
The number of data lines does not match the number of lines in the range. The data is X rows, but the range is 1. (Line 55, file "code")
The number of X is in the line of var thread, it was the number of threads that includedreadof the corresponding mail in GmailApp.search.
function getMailandInsert () {
var sheet = SpreadsheetApp.getActiveSheet ();
// start potision
var start = 0;
// Maximum number of emails to retrieve
var max = 5;
// number of data columns to insert into the spreadsheet
var insertCol = 6;
// Get incoming email that matches the conditions
var threads = GmailApp.search ('is: unread from: ([email protected]) subject: (wakaran)', start, max);
// number of threads matching the condition
var length = threads.length;
// The last row of the sheet where the data will be saved. That is, the insertion start position
var row = sheet.getLastRow () + 1;
// Array for storing the acquired mail contents
var resultArr = new Array ();
for (var n in threads) {
var the = threads [n];
// get mail in thread
var msgs = the.getMessages ();
// Analyze the mail in the thread and store it in resultArr
returnData (msgs, resultArr);
// Mark the acquired thread as read
the.markRead ();
Utilities.sleep (1000);
}
if (length! = 0) {
sheet.getRange (row, 1, length, insertCol) .setValues (resultArr);// save data
// ######## Above is the line where the error occurred. The error message says that the number of data lines is more than one line ... ##########
// The contents of getRange are (final line + 1,1, number of threads, 6)
}
}
function returnData (msgs, resArray) {
for (m in msgs) {
try {
var tempArray = new Array ();
var msg = msgs [m];
// email date
var date = msg.getDate ();
// E-mail sender address
var from = msg.getFrom ();
// Email subject
var subject = msg.getSubject ();
// Get email body with PlainBody
var body = msg.getPlainBody ();
// Parse the body with an XML parser
var xml = XmlService.parse (body);
// Get the root element of the XML analysis result
var root = xml.getRootElement ();
// Specify each child element in XML and get its value.
var hinichi = root.getChild ("hinichi"). getText ();
var zzz = root.getChild ("zzz"). getText ();
var xxx = root.getChild ("xxx"). getText ();
var ddd = root.getChild ("ddd"). getText ();
var vvv = root.getChild ("vvv"). getText ();
var etc = root.getChild ("etc"). getText ();
// store each value in an array
tempArray [0] = hinichi;
tempArray [1] = zzz;
tempArray [2] = ddd;
tempArray [3] = eisei;
tempArray [4] = vvv;
tempArray [5] = etc;
// add array to the end with push
resArray.push (tempArray);
} catch (e) {
Logger.log ("Error:" + e);
}
}
}
Only the first email worked, but it didn't work after the second one.
It may not be enough, but thank you.
chrome latest version
-
Answer # 1
Related articles
- send error for batch email sending of google apps script
- google apps script - gas gives an error on the server when executing a trigger that fires in time
- google apps script - i get an error about pushing bubble messages with line messaging api in gas
- google apps script - oauth error after line login with gas (invalid_grant, authorization code expired or incompatible)
- google apps script - solution for error message "parameter () does not match the method signature of spreadsheetappsheetget
- google apps script - debugging in gas, but not triggering
- google apps script - i want to create a list of file names and urls of files in multiple folders on google drive
- google apps script - i want to send an email with gas based on the list in the spreadsheet i want to improve the symptom of bein
- i want to make an array of scraping results using cheeriogs in google apps script and reflect it in a spreadsheet
- google apps script - i want to know the coding to export from a spreadsheet to a document with line breaks in gas
- "paste only value" is not reflected in google apps script
- google apps script - i want to make a script that opens an external url with gas!
- google apps script - how to get the value of the merged cell
- google apps script - the link from gas to line login says "in a frame because it set'x-frame-options' to'deny'"
- google apps script - schedule is not reflected in the calendar from google spreadsheet
- google apps script - i can't search for a character string in gas
- google apps script - i want to get the selected rows in a gas spreadsheet
- google apps script - how to make the string search in gas case insensitive
- google apps script - i want to move to the original data extracted by the query function
- google apps script - please tell me how to set the form answer to be written to a spreadsheet
Related questions
- javascript - i want to make an automatic reply with gas
- google apps script - when sending google spreadsheet data by email, the format of date data changes
- gmail automatic transfer spreadsheet/gas use
- java - "gas" i want to reflect the information of the error mail that returns to gmail in the spreadsheet
- google apps script - when sending the response contents of a google form from a spreadsheet to an email, if you re-edit the form
- google apps script - i want to extract specific characters with gas and transfer them to cells
- google apps script - i want to allow access requests to gas i want to allow it, but i can't because of an internal error
- google apps script - how to create if condition from some characters in gas
- javascript - inquiry email is reflected in the spreadsheet using gas
- gmail - how to extract specific characters from text with gas
I just read it briefly, but it pushes
resultArr
bymsgs.length
number of times in thereturnDatafunction
If the email thread contains multiple emails, or if an error occurs in
returnData
So,
length
andresultArr.length
may not match.