Google Contact “Birthday” field not showing when s

2019-08-24 23:07发布

I am having a problem in Apps Script setting the Birthday field in a Google Contact. I have a Form with a "User's Date of Birth" field and my code is called upon FormSubmit from the receiving spreadsheet. It looks like this:

  // h/t @tehhowch for this mapping solution
  var months = ContactsApp.Month;
  var monthToEnum = {
    1: months.JANUARY,
    2: months.FEBRUARY,
    3: months.MARCH,
    ...,
    12: months.DECEMBER
  };

  // get the date from the event parameter e
  var d = new Date(e.namedValues["User's Date of Birth"]);
  var birthdayMonth = d.getMonth()+1;  // getMonth() returns offset 0
  var birthdayDay   = d.getDate();
  var birthdayYear  = d.getFullYear();
  var monthEnum     = monthToEnum[birthdayMonth];

  Logger.log("Birthday: " + birthdayMonth + "/" + birthdayDay 
           + "/" + birthdayYear + " and " + monthEnum);

  contact.addDate(ContactsApp.Field.BIRTHDAY, monthEnum, 
                  birthdayDay, birthdayYear);

  Logger.log("formSubmittedSheetNewPatient: contact Birthday = "
           + contact.getDates(ContactsApp.Field.BIRTHDAY)[0].getMonth());

The first log correctly shows "Birthday: 2/21/1912 and FEBRUARY" and the second is "contact Birthday = FEBRUARY" so the code works. Then I add the new contact to an existing group. But when I look at the new contact in Google Contacts the default built-in Birthday field is empty and there is no other Birthday field. All the other fields I'm setting in the new contact are there. Does anyone see what I'm doing wrong, or is there a bug in the Contact Birthday field code?

0条回答
登录 后发表回答