Google Contact “Birthday” field not showing when set from Apps Script
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?
javascript google-apps-script google-contacts
add a comment |
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?
javascript google-apps-script google-contacts
In my environment, I cannot replicate your situation. So can you provide the script for replicating it? It will help users think of about the solution of your issue.
– Tanaike
Jan 1 at 2:56
Thanks for your reply. I enclosed my code. It's straightforward and the contact object clearly has the Birthday field because I can retrieve it right after in the logging statement. I go to my contacts and I have the new contact I just created and all the other fields, but the Birthday field, which seems to be a standard field, is empty. It just doesn't make sense.
– jeff
Jan 1 at 5:00
for some time, the birthday field no longer displays the date but when I ask with script "Contacts[0].getDates(ContactsApp.Field.BIRTHDAY);" the information is still there. It seems that it's a problem of this field for information, I entered the birthday directly in the Google Contact, I did not use the script.
– Christian
Jan 6 at 10:27
@Christian - very interesting. I'm going to have to dig into whether this is a known but with Contacts. Thanks for your comment here.
– jeff
Jan 8 at 13:10
@Christian - I just tried it an you are right! Gotta be a Contacts bug.
– jeff
Jan 8 at 13:12
add a comment |
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?
javascript google-apps-script google-contacts
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?
javascript google-apps-script google-contacts
javascript google-apps-script google-contacts
asked Dec 31 '18 at 16:31
jeffjeff
226
226
In my environment, I cannot replicate your situation. So can you provide the script for replicating it? It will help users think of about the solution of your issue.
– Tanaike
Jan 1 at 2:56
Thanks for your reply. I enclosed my code. It's straightforward and the contact object clearly has the Birthday field because I can retrieve it right after in the logging statement. I go to my contacts and I have the new contact I just created and all the other fields, but the Birthday field, which seems to be a standard field, is empty. It just doesn't make sense.
– jeff
Jan 1 at 5:00
for some time, the birthday field no longer displays the date but when I ask with script "Contacts[0].getDates(ContactsApp.Field.BIRTHDAY);" the information is still there. It seems that it's a problem of this field for information, I entered the birthday directly in the Google Contact, I did not use the script.
– Christian
Jan 6 at 10:27
@Christian - very interesting. I'm going to have to dig into whether this is a known but with Contacts. Thanks for your comment here.
– jeff
Jan 8 at 13:10
@Christian - I just tried it an you are right! Gotta be a Contacts bug.
– jeff
Jan 8 at 13:12
add a comment |
In my environment, I cannot replicate your situation. So can you provide the script for replicating it? It will help users think of about the solution of your issue.
– Tanaike
Jan 1 at 2:56
Thanks for your reply. I enclosed my code. It's straightforward and the contact object clearly has the Birthday field because I can retrieve it right after in the logging statement. I go to my contacts and I have the new contact I just created and all the other fields, but the Birthday field, which seems to be a standard field, is empty. It just doesn't make sense.
– jeff
Jan 1 at 5:00
for some time, the birthday field no longer displays the date but when I ask with script "Contacts[0].getDates(ContactsApp.Field.BIRTHDAY);" the information is still there. It seems that it's a problem of this field for information, I entered the birthday directly in the Google Contact, I did not use the script.
– Christian
Jan 6 at 10:27
@Christian - very interesting. I'm going to have to dig into whether this is a known but with Contacts. Thanks for your comment here.
– jeff
Jan 8 at 13:10
@Christian - I just tried it an you are right! Gotta be a Contacts bug.
– jeff
Jan 8 at 13:12
In my environment, I cannot replicate your situation. So can you provide the script for replicating it? It will help users think of about the solution of your issue.
– Tanaike
Jan 1 at 2:56
In my environment, I cannot replicate your situation. So can you provide the script for replicating it? It will help users think of about the solution of your issue.
– Tanaike
Jan 1 at 2:56
Thanks for your reply. I enclosed my code. It's straightforward and the contact object clearly has the Birthday field because I can retrieve it right after in the logging statement. I go to my contacts and I have the new contact I just created and all the other fields, but the Birthday field, which seems to be a standard field, is empty. It just doesn't make sense.
– jeff
Jan 1 at 5:00
Thanks for your reply. I enclosed my code. It's straightforward and the contact object clearly has the Birthday field because I can retrieve it right after in the logging statement. I go to my contacts and I have the new contact I just created and all the other fields, but the Birthday field, which seems to be a standard field, is empty. It just doesn't make sense.
– jeff
Jan 1 at 5:00
for some time, the birthday field no longer displays the date but when I ask with script "Contacts[0].getDates(ContactsApp.Field.BIRTHDAY);" the information is still there. It seems that it's a problem of this field for information, I entered the birthday directly in the Google Contact, I did not use the script.
– Christian
Jan 6 at 10:27
for some time, the birthday field no longer displays the date but when I ask with script "Contacts[0].getDates(ContactsApp.Field.BIRTHDAY);" the information is still there. It seems that it's a problem of this field for information, I entered the birthday directly in the Google Contact, I did not use the script.
– Christian
Jan 6 at 10:27
@Christian - very interesting. I'm going to have to dig into whether this is a known but with Contacts. Thanks for your comment here.
– jeff
Jan 8 at 13:10
@Christian - very interesting. I'm going to have to dig into whether this is a known but with Contacts. Thanks for your comment here.
– jeff
Jan 8 at 13:10
@Christian - I just tried it an you are right! Gotta be a Contacts bug.
– jeff
Jan 8 at 13:12
@Christian - I just tried it an you are right! Gotta be a Contacts bug.
– jeff
Jan 8 at 13:12
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53989513%2fgoogle-contact-birthday-field-not-showing-when-set-from-apps-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53989513%2fgoogle-contact-birthday-field-not-showing-when-set-from-apps-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
In my environment, I cannot replicate your situation. So can you provide the script for replicating it? It will help users think of about the solution of your issue.
– Tanaike
Jan 1 at 2:56
Thanks for your reply. I enclosed my code. It's straightforward and the contact object clearly has the Birthday field because I can retrieve it right after in the logging statement. I go to my contacts and I have the new contact I just created and all the other fields, but the Birthday field, which seems to be a standard field, is empty. It just doesn't make sense.
– jeff
Jan 1 at 5:00
for some time, the birthday field no longer displays the date but when I ask with script "Contacts[0].getDates(ContactsApp.Field.BIRTHDAY);" the information is still there. It seems that it's a problem of this field for information, I entered the birthday directly in the Google Contact, I did not use the script.
– Christian
Jan 6 at 10:27
@Christian - very interesting. I'm going to have to dig into whether this is a known but with Contacts. Thanks for your comment here.
– jeff
Jan 8 at 13:10
@Christian - I just tried it an you are right! Gotta be a Contacts bug.
– jeff
Jan 8 at 13:12