I actually wanted to send MoM on daily basis, so I created a folder where I put all MoM docs and title them with the date for which it was created. Then script reads it on the day and send it to fixed email address, but now we inserted the attendees inside the google docs like this :-
Is there any way I can get those email address/user email address mentioned there.
Script I was using earlier was this :-
function sendMinutes() {
const folder = DriveApp.getFolderById('Filder id')
const today = Utilities.formatDate(new Date(),Session.getScriptTimeZone(),'MMM dd,yyyy')
const files = folder.searchFiles(`title contains '${today}'`)
while(files.hasNext())
{
let file= files.next()
let doc = DocumentApp.openById(file.getId())
let body = doc.getBody()
let parag = body.getParagraphs().forEach(r=> {
.....
})
}
}
I got how to get email but, it is just returning first email now, i need to get every email address as ElementType as PERSON:-
body.findElement(DocumentApp.ElementType.PERSON).getElement().asPerson().getEmail()
Thanks
CodePudding user response:
Body.findElement
has several forms, one of them use two parameters, the second one is the start point for finding the next element. Use this method form together with a loop. In the following example a while
statement is being used:
function logEmailsFromPersonChips() {
const doc = DocumentApp.getActiveDocument();
const body = doc.getBody();
let found;
const emails = [];
while ( found = body.findElement(DocumentApp.ElementType.PERSON,found)){
const email = found.getElement().asPerson().getEmail();
emails.push(email);
}
console.log(JSON.stringify(emails))
}