A Function to update a field in all contact records under an account?

A Function to update a field in all contact records under an account?

I largely understanding the basics of writing functions with a 1 to 1 relationship, but I'm missing something with a one to many.  I'm sure i'll need to make use of for loops, i'm just struggling to pull the information correctly.



So i have 2 use cases.

1.) I want to create a button on accounts that will update all related contacts address.
2.) I want to create an automatic function that will copy over account.AccountNotes into a read only field on contacts.AccountNotes.   The idea being sometimes i pull up a contacts records and don't realize a peculiarity of an account.  I'll trigger this every time the Account.AccountNotes field is updated, and also create another function every time a contact is created to pull this info from the Account Notes.

Just to add i have a custom multiline text field called Account_Notes.

So i'm working on #2 first.  Here is what I have so far and where i'm struggling:


  1. actid=XXXXXXX;
  2. actrec = zoho.crm.getRecordById("Accounts", actid);
  3. actnotes=actrec.get("Account_Notes");
  4. relcontrecs=zoho.crm.getRelatedRecords("Contacts","Accounts",actid);

  5. info relcontrecs;

  6. relcontids=relcontrecs.getJSON("id");
  7. info relcontids;

Now my expectation is for 'info relcontids' to return a list of 2 id's for the 2 contacts associated with the record I am testing with, but it is only returning a single id.  My next step would be to use a list of ID's in a for loop to then map the account.account_notes to the contact.account_notes field.  Not sure if that would be ideal or not though.