简体   繁体   中英

How do I know if a Google script is actually running?

Am an admitted newby here. Please bear with me. I hope I am asking intelligent questions. If not, please assist so I can tap into your collective wisdom.

I have unwanted emails in my Google Gmail account.
Many are marketing related, and definitely unnecessary after 7 days.
Browser Google or Firefox
OS WIN 7 Pro.

Thus I wish To delete emails over 7 days that have the delete me folder assigned, and archive other non delete me assignment.

The code for a small sample script that suggests the issue, which I found searching for a simple solution is:

function cleanUp() {
  var delayDays = 7 // Enter # of days before messages are moved to trash

  var maxDate = new Date();
  maxDate.setDate(maxDate.getDate()-delayDays);

  var label = GmailApp.getUserLabelByName("delete me");
  var threads = label.getThreads();
  for (var i = 0; i < threads.length; i++) {
    if (threads[i].getLastMessageDate()<maxDate)
    {
      threads[i].moveToTrash();
    }
  }
}

function archiveInbox() {
  // Every thread in your Inbox that is read, older than seven days, and not labeled "delete me".
  var threads = GmailApp.search('label:inbox is:read older_than:2d -label:"delete me"');
  for (var i = 0; i < threads.length; i++) {
    threads[i].moveToArchive();
  }
}

My questions are: How do I know "delete me" is running? I click on run and then it says it is, but nothing happens and the size of the number of emails in my gmail account is the same.

Also ran the 'archive me' script and nothing seems to happen even though it shows it is running.

If you look into the following link, it provides excellent steps for troubleshooting / debugging your code: https://developers.google.com/apps-script/troubleshooting

It also explains what Shahar and Arun are discussing but it more detail.

For your issue, you can't really compare the two dates as is. You should do:

if (threads[i].getLastMessageDate()< new Date(maxDate))

Cheers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM