When I run the code below in debug mode I get the expected value on the first iteration of the for loop but null on the second as seen on the images:
First iteration:
Second iteration:
What am I dong wrong?
The code I am using is:
var newer_than = ' newer_than:2d'; //added for faster debugging
var subjectIdentifier = '"Ingress Portal Submitted: "';
var searchString = 'subject:'+subjectIdentifier+newer_than;
function getPortalName(string) {
var myRegexp = /: (.+)/g;
var match = myRegexp.exec(string);
var portalName = match[1];
return portalName;
}
function getPortalsSubmitted() {
var threads = GmailApp.search(searchString);
for (i=0; i<threads.length; i++) {
var subject = threads[i].getFirstMessageSubject();
var portalName = getPortalName(subject);
var subDate = threads[i].getMessages()[0].getDate();
Logger.log([portalName,subDate]);
}
}
function updatePortals() {
var threads = GmailApp.search('subject:"Ingress Portal"');
for (i=0; i<threads.length; i++) {
Logger.log(threads[i].getFirstMessageSubject());
}
}