autpopulate account custom address fields to contact address field

hello,

How can i auto populate account custom address fields to contact address fields on selecting account from contact edit view.

As it happens I was working on something very similar today :wink:

You use JavaScript to Override the onclick event on the account selection button.

If you inspect the button element it contains:


open_popup( "Accounts",  600,  400,  "",  true,  false,  {"call_back_function":"set_return","form_name":"EditView","field_to_name_array":{"id":"account_id","name":"account_name","billing_address_street":"primary_address_street","billing_address_city":"primary_address_city","billing_address_state":"primary_address_state","billing_address_postalcode":"primary_address_postalcode","billing_address_country":"primary_address_country","phone_office":"phone_work"}},  "single",  true );

You need to add your custom fields to the field_to_name_array example: “field_from_account”:“field_to_populate”

In order to override the onclick event add a custom js file like here : http://sugarmods.co.uk/adding-custom-javascript-to-a-view-in-sugarcrm

Then in the the file do something like this to override the button :


document.getElementById("btn_account_name").setAttribute('onclick','open_popup( "Accounts",  600,  400,  "",  true,  false,  {"call_back_function":"set_return","form_name":"EditView","field_to_name_array":{"id":"billing_account_id","name":"billing_account","billing_address_street":"billing_address_street","billing_address_city":"billing_address_city","billing_address_state":"billing_address_state","billing_address_postalcode":"billing_address_postalcode","billing_address_country":"billing_address_country","sage_account_ref_c":"sage_ref_billing"}},  "single",  true );');
    

Make sense?