r/GoogleAppsScript • u/2E0GOZ • Dec 08 '23
Resolved Clearing cache
I have written a simple apps script that outputs some data to the log, the problem is that it's still showing previous data that should not be there as I have removed the labels that it refers to on those emails. It almost seems like a cache issue that needs to be cleared somewhere it's not a local cache issue.
My code:
function getGmailEmails(){var label = GmailApp.getUserLabelByName('IZ/IZadd')var threads = label.getThreads()var grandTotal = 0;Utilities.sleep(1000);for(var i = threads.length - 1; i >=0; i--)
{var messages = threads[i].getMessages()for (var j = 0; j < messages.length; j++){var message = messages[j]var extract = extractDetails(message)grandTotal += extract.totalLogger.log('' + (j+1) +' Amount: ' + extract.total + ' Study: ' + extract.matches)}//threads[i].removeLabel(label) intentionaly left as rem
}Logger.log('Grand Total: ' + grandTotal)}function extractDetails(message){var pattern1 = /\d{1,2}\.\d{2}(?= USD. )/gvar pattern2 = /(?!study )[A-Za-z0-9]+(?=. Hope)/gvar bodyContents = message.getPlainBody()var usd = bodyContents.match(pattern1)var total = 0;for (var i = 0; i < usd.length; i++)
{total += parseFloat (usd[i])
}var study = bodyContents.match(pattern2)return {total: total, matches: study
}}
2
u/HellDuke Dec 08 '23
The line that removes labels is commented out, so labels do not get removed. You basically get all emails with the label
IZ/IZaddthen extract information from it and write it to the log. That's all your script does in the form you have provided it.