Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8777975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:24:41+00:00 2026-06-13T19:24:41+00:00

I am trying to delete a custom field based on its value, but it

  • 0

I am trying to delete a custom field based on its value, but it dies in testing. Current code:

function testDelete2() {
  var contacts = ContactsApp.findContactGroup('test').getContacts();    

    for (var i in contacts) {

    var checkfield = contacts[i].getUserDefinedField('testlabel')

        if (checkfield == 'testvalue') {

          var customFields = contacts[i].getCustomFields();
          customFields.deleteCustomField('testlabel');
        }
    }
}

I get this error: TypeError: Cannot find function deleteCustomField in object CustomField.

No idea what that means. Please help. I’ve read this page over and over and it’s no help: https://developers.google.com/apps-script/service_contacts

I even tried this variation which didn’t work:

      customFields.getLabel('testlabel').deleteCustomField();

Also, is there any simple documentation with samples anywhere of how to deal with google contacts custom fields? Adding, deleting, just getting the value all seem impossible. I appreciate the help with this question, but also don’t mind finding a guide somewhere with simple samples to look at.

Using Serge’s great code as inspiration came up with this code for deletion (will add full code with delete/add soon):

UPDATE: simplified process (don’t know why didn’t try this out in beginning, maybe I did but was coding wrong, anyway) by taking out the delete/add custom field and just updating that custom field’s value

function testUpdateDues() {

var duescos = ContactsApp.findContactGroup('z8 - Assoc').getContacts();   

for (var i in duescos) {

var customFields = duescos[i].getCustomFields();

for (var n in customFields) {

if (customFields[n].getLabel() == 'Dues Amount' && customFields[n].getValue() == 'unstated'){
customFields[n].setValue('$ 500');
}
}
}
}

Final Edit allows me to add/edit any custom field based on google contact group assignment (thanks Serge for the assist!!) with time based triggers in the script:

function UpdateRegion1() {
  UpdateCustomField('Reg 1 - Pan', 'Region' , 'Region 1 - Panhandle');
}

    function UpdateCustomField(group, customlabel, customvalue) {
  var contacts = ContactsApp.findContactGroup(group).getContacts();
  for (var i in contacts) {
    var fields = new Array();
    var customFields = contacts[i].getCustomFields(); 
    for(var n in customFields) {
      fields.push(customFields[n].getLabel());
    }
    if (fields.indexOf(customlabel)==-1){
      contacts[i].addCustomField(customlabel, customvalue);
    }
    for(var j in customFields) {
      if (customFields[j].getLabel() == customlabel && customFields[j].getValue() != customvalue){
        customFields[j].setValue(customvalue);
      }
    }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:24:43+00:00Added an answer on June 13, 2026 at 7:24 pm

    Here is how it works, see comments in code

    function testDelete2() {
      var contacts = ContactsApp.findContactGroup('test').getContacts();    
    
        for (var i in contacts) {
    
          var customFields = contacts[i].getCustomFields();// returns an array of custom fields
    
            for(var n in customFields) { // iterate the custom fields
    
    Logger.log(customFields[n].getLabel()+' = '+customFields[n].getValue()) // EDIT : just changed this line to show the label AND the value
    
              if(customFields[n].getLabel() == 'testlabel'){ // compare the label with your criteria
    
              customFields[n].deleteCustomField();// if true then delete
          }
        }
      }
    }
    

    I hope this answers also (in a way) to your second request… As you can see it’s all about using these functions the right way. I’d suggest you make use of the logger to helps you. It allows to see what type of variable is returned … ( just between you and me, that’s how I did ‘debug’ your code…. but please keep this confidential 😉

    I saw on your profile that you are “Using google apps script because I have to” but I’m sure (well I hope) you’ll love it in the end.

    EDIT 2 :
    A script to add a custom field when not present

    function addCustomField() {
      var contacts = ContactsApp.findContactGroup('Insas').getContacts();    
    
        for (var i in contacts) {
    var fields = new Array()
          var customFields = contacts[i].getCustomFields()
            for(var n in customFields) {
            fields.push(customFields[n].getLabel())
            }
    Logger.log(fields)
    
          if(fields.indexOf('insas')==-1){
    
              contacts[i].addCustomField('insas','oui')
          }
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to delete a cookie with this function , but it doesnt
I have encountered this error when trying to delete a cell, using a custom
I am trying to delete the data present in the dataset with following code:
I'm trying to create a custom delete rule on a relationship between a parent
I'm trying to add a delete button to a custom div. However when the
I'm trying to delete items from a ListView using a custom adapter which extends
I am trying to delete a sub-column of a super column family. I tried
I am trying to delete MySQL table rows from a Web page using Perl.
I'm trying to delete a specific line by id from a file in C++
I'm trying to delete certain lines from a file. My file is a .txt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.