Google Contact “Birthday” field not showing when set from Apps Script

本小妞迷上赌 提交于 2019-12-24 18:48:13

问题


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?

来源:https://stackoverflow.com/questions/53989513/google-contact-birthday-field-not-showing-when-set-from-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!