I would first like to tell you as what I am trying to accomplish from this script. I am not very familiar with writing scripts, however I have succesfully tested the below script but now when I try to do some changes in it, I get errors
I want to accomplish the following. 1. The Loop Should run for 100 Messages only. 2. The Data pointer is skipping Messages, and changing labels of much more than 100 Messages. 3. Label to remain as "Pending" where data is not Grabbed, and change to "Done" where it is grabbed.
function GrabFacebookLP() {
var ss = SpreadsheetApp.getActiveSheet();
var label = GmailApp.getUserLabelByName("Pending");
var threads = label.getThreads();
var label2 = GmailApp.createLabel("Done")
for (var i=0; i<100; i++) {
var tmp,
message = threads[i].getMessages()[0],
subject = message.getSubject(),
content = message.getPlainBody(),
date = message.getDate();
// Get the plain text body of the email message
// You may also use getRawContent() for parsing HTML
// Implement Parsing rules using regular expressions
if (content) {
tmp = content.match(/Name :\s*([A-Za-z0-9\s]+)(\r?\n)/);
var username = (tmp && tmp[1]) ? tmp[1].trim() : 'No username';
tmp = content.match(/Email :\s*([A-Za-z0-9@._-]+)/);
var email = (tmp && tmp[1]) ? tmp[1].trim() : 'No email';
tmp = content.match(/Phone number :\s*([A-Za-z0-9\s]+)(\r?\n)/);
var phone = (tmp && tmp[1]) ? tmp[1] : 'No phone';
tmp = content.match(/Services :\s*([A-Za-z0-9\s]+)(\r?\n)/);
var services = (tmp && tmp[1]) ? tmp[1].trim() : 'No Services Chosen/Mentioned';
ss.appendRow([date, subject, username, email, phone, services]);
} // End if
threads[i].addLabel(label2);
threads[i].removeLabel(label);
} // End for loop
}
Aucun commentaire:
Enregistrer un commentaire