0

All

I have a google apps script to create a shared contact in a GSuite domain.

  Logger.clear();
  debug("Begin createSharedContacts");
  var rangeDataValues = SpreadsheetApp.getActiveSheet().getRange(dataA1notation).getValues();
  var sharedContact = null;
  var sharedContactCustomField = null;
  var sharedContactAlt1EmailField = null;
  // loop trough all data, but process only the ones with a StudentNr
  for (var i = 0; (i < rangeDataValues.length) && (rangeDataValues[i][0] != ""); i++) {
      var rangeDataValueRow = rangeDataValues[i];
      sharedContact = SharedContactsApp.createContact(rangeDataValueRow[1], rangeDataValueRow[2], "xx@yy.zz");
      sharedContactCustomField = sharedContact.addCustomField("Stamnummer",rangeDataValueRow[0]);
      sharedContactAlt1EmailField = sharedContact.addEmail(ContactsApp.Field.HOME_EMAIL, rangeDataValueRow[8]);
      debug(Object.prototype.toString.call(sharedContactAlt1EmailField));
      debug(JSON.stringify(sharedContactAlt1EmailField));
      sharedContactAlt1EmailField.setDisplayName("("+rangeDataValueRow[6]+") "+rangeDataValueRow[7]+", "+rangeDataValueRow[6]);
      SpreadsheetApp.getActiveSheet().getRange(i+3,5).setValue(sharedContact.getId());
  }
  debug("End createSharedContacts");

When I execute this peace op code I get the error:

TypeError: Cannot find function setAsPrimary  in object [object Object].

Any input on how to solve this.

Kind Regards Olivier

  • I suggest you edit your sample code and make a much simpler test with hardcoded data and then report the results back here including the full error message and the line number on which it occurs etc. If you can't reproduce it it may point to an issue in your data. – Peter Jun 18 '17 at 01:32
  • It looks like you are creating a contact and giving it an email address but not stipulating which email you wish to be the primary: https://developers.google.com/apps-script/reference/contacts/address-field#setAsPrimary() – joshnik Jun 22 '17 at 21:03

0 Answers0