Reputation: 160
I get email notifications for doctors appointments etc, but only need to keep the most current. I am trying to create a google script to archive older reminders when I get a new reminder from the same provider.
The basic way the script is intended to work is a gmail filter adds a tag to any new reminders that come in, which the script then uses to see if there is an existing reminder from that provider (through checking another tag), then acts accordingly (by changing tags and archiving messages)
However, I keep getting the error "Cannot find function removeLabel in object Gmail Thread" on line 34 even though everything looks right to me
//get the threads with the new message label (new threads that need to be checked by the function)
var newThreadsLabel = GmailApp.getUserLabelByName("@Automate/Keep Only One/New Message")
var newThreads = newThreadsLabel.getThreads(0, 400);
//get the current threads (messages that were previously defined as the "current reminder")
var currentThreadsLabel = GmailApp.getUserLabelByName("@Automate/Keep Only One/Current Reminder")
var currentThreads = currentThreadsLabel.getThreads(0, 400);
//loop through the new threads
for (var i = 0; i < newThreads.length; i++){
var newThread = newThreads[i];
//get the subject for the newThread
var subject = newThread.getFirstMessageSubject();
//loop through the "current reminder" threads to see if they are now old (they have the same subject as the "new message"), archive them if they are, then label the "new thread" as the "current thread"
for (var i = 0; i < currentThreads.length; i++){
var currentThread = currentThreads[i];
//check if any of the "current threads" have the same subject as the "new thread", and is not the "new thread" itself
if(currentThread.getFirstMessageSubject() == subject){
//Now, we need to make sure that we don't archive the current thead itself (in some cases gmail may have bundled them into the same thread)
//Get the labels on the "current thread"
var labels = currentThreads[i].getLabels();
//check to see if the labels on the "current thread" include the newThreadsLabel
if(labels.indexOf(newThreadsLabel) !== -1){
//if the "new thread" and "current thread" are the same dont do anything because we don't need to archive it
}else{
//if they are not the same, archive the currentThread and remove the currentThreadsLabel
currentThread.removelabel(currentThreadsLabel);
currentThread.moveToArchive();
}
}
}
//remove the new thread label, then add the current thread label (new thread becomes the "current reminder" thread)
newThread.removeLabel(newThreadsLabel);
newThread.addLabel(currentThreadsLabel);
}
}
I have double and triple checked the documentation, and this seems to be the right way to use removeLabel. Why would I be getting this error?
Upvotes: 0
Views: 242
Reputation: 64072
Are you missing a capital "L" ?
I believe that this: else{
//if they are not the same, archive the currentThread and remove the currentThreadsLabel
currentThread.removelabel(currentThreadsLabel);
currentThread.moveToArchive();
should be like this: else{
//if they are not the same, archive the currentThread and remove the currentThreadsLabel
currentThread.removeLabel(currentThreadsLabel);
currentThread.moveToArchive();
Upvotes: 3