I'm using Google Apps Script to iterate through my contacts and print name, address, email and phone numbers to a document.
I want the name in style "Heading 2" and the rest in style "Normal text".
How can I do this?
Here's what I've got so far but it makes the whole paragraph Heading 2, instead of just the name.
var myContacts = ContactsApp.findContactGroup('Some group').getContacts();
for (i=0; i < myContacts.length; i++)
{
var fullName = myContacts[i].getFullName();
if (fullName == '')
fullName = 'Anonymous';
var contactPara = doc.appendParagraph(fullName);
contactPara.setHeading(DocumentApp.ParagraphHeading.HEADING2);
var homeAddresses = myContacts[i].getAddresses(ContactsApp.Field.HOME_ADDRESS);
var homeAddress = '';
if (homeAddresses.length > 0)
contactPara.appendText('\n' + homeAddresses[0].getAddress());
contactPara.appendText('\n' + 'Email: ' + myContacts[i].getPrimaryEmail());
var mobilePhones = myContacts[i].getPhones(ContactsApp.Field.MOBILE_PHONE);
if (mobilePhones.length > 0)
contactPara.appendText('\n' + 'Mobile phone: ' + mobilePhones[0].getPhoneNumber());
var homePhones = myContacts[i].getPhones(ContactsApp.Field.HOME_PHONE);
if (homePhones.length > 0)
contactPara.appendText('\n' + 'Home phone: ' + homePhones[0].getPhoneNumber());
var workPhones = myContacts[i].getPhones(ContactsApp.Field.WORK_PHONE);
if (workPhones.length > 0)
contactPara.appendText('\n' + 'Work phone: ' + workPhones[0].getPhoneNumber());
}
Alternatively, if there's a better way to do what I want them please suggest it.