- Where Developers Learn, Share, & Build Careers
I am trying to delete a custom field based on my value, but it dies in the trial. Current code:
function testDelete2 () {var contact = ContactsApp.findContactGroup ('test'). GetContacts (); (Var i in contact) {var checkfield = contact [i] .getUserDefinedField ('testlabel') if (checkfield == 'testvalue') {var customfiled = contact [i] .getCustomFields (); CustomFields.deleteCustomField ('testlabel'); }}} I get this error: TypeError: Function deleteCustomField in object custom field is not found.
Nobody has this meaning. Please help. I have read this page more and it is not of any help:
I also tried to make this change which does not work:
customFields.getLabel (' Testlabel ') .deleteCustomField (); Also, are Google Contacts sampling anywhere to deal with custom fields? It is impossible to add, remove, just get the value, I appreciate the help with this question, but I do not have to find a guide somewhere with simple samples to see.
In order to use Serge's great code as inspiration this code came to remove (add / remove soon with complete code added):
Update: Removing / Add Custom Field and Simply Updating the Value of Custom Fields Pre> function testUpdateDues () {var duescos = ContactsApp.findContactGroup ('z8 - Assoc '). GetContacts (); For (data in var i) {var customfilled = datasus [i] .getCustomFields (); (Custom filtered by var n) (if (custom field [n] .getLabel () == 'outstanding balance' & amp;; & customfield [n] .getValue () == 'fluctuating') {custom field [ N] .setValue '$ 500'); }}}} Last edit permissions to add / edit a custom field based on Google contact group assignment (thanks for the help!) Triggers based on script: function UpdateRegion1 () {UpdateCustomField ('Reg 1 - Pan', 'Region', 'Region 1 - Panhandle'); } Function UpdateCustomField (group, custom label, customwall) {var contact = ContactsApp.findContactGroup (group) .getContacts (); For (var i in contact) {var fields = new Array (); Var customfiled = contact [i] .getCustomFields (); (Custom field in var n) {fields.push (customfield [n] .getLabel ()); } If (fields.indexOf (customlabel) == - 1) {contact [i] .addCustomField (custom label, custom volume); } (In customfield var j) {if (customfields [j] .getLabel () == Custom labels & amp; customfield [J] .getValue (!!) = CustomVolume) {customfield [j] .setValue (customvalue) ; }}}}}
How it works, view comments in code
function testDelete2 () {var contact = ContactsApp.findContactGroup ('test'). GetContacts (); For (contact in var i) {var customfilled = contact [i] .getCustomFields (); Returns an array of custom fields for // // custom field (var n) in it (// custom field logger.log repeat (custom field [n] .getLabel () + '=' + customFields [n] .getValue () ) / Edit: To display labels and values just this line has been changed if (custom field [n] .getLabel () == 'testlabel') {// Compare labels with your criteria customfield [n] .deleteCustomField (); // If true then delete}}}} I hope this answer also (in a way) your second request ... as you can see that these tasks It's all about using the right way. I suggest you use logger to help you see what types of variables are back ... (just between you and me, I had 'debug' my code but .... but please keep it confidential -)
I saw on your profile you are using " Google Apps Script because I " but I'm sure (well I hope) Edit 2: Add a custom field to a script when function addCustomField () {var contacts = ContactsApp .findContactGroup ('INSAS') getContacts () .; {Var contacts in var i log (fields) if (fields.indexOf ('insas') == - 1) {contact [i] .addCustomField ('insas', 'oui')}}}
Comments
Post a Comment