When a Contact is edited to move them to different Account: how can I get more fields copied across?

(NB:- I look after SuiteCRM for the 2 staff here in my company that use it)

Suite - and Sugar before - has always updated the Contacts ‘Primary Address’ fields (about 5 of them), : by pulling fields from the Account they were just moved to: using from Accounts the similar but different named fields: ‘Billing Address’ etc

There’s a popUp that asks if you are OK with the new values:

I want to add one more field, to be also copied in the same way.

I have looked hard: but can’t find how to!

This file shows the mappings between the fields in Accounts and Contacts:

  • include/SugarObjects/templates/person/Person.php
public function populateRelatedBean(SugarBean $newBean) {parent::populateRelatedBean($newBean);
    if ($newBean instanceof Company) {
        $newBean->phone_fax = $this->phone_fax;
        $newBean->phone_office = $this->phone_work;
        $newBean->phone_alternate = $this->phone_other;
        $newBean->email1 = $this->email1;
        $this->add_address_streets('primary_address_street');
        $newBean->billing_address_street = $this->primary_address_street;
        $newBean->billing_address_city = $this->primary_address_city;
        $newBean->billing_address_state = $this->primary_address_state;
        $newBean->billing_address_postalcode = $this->primary_address_postalcode;
        $newBean->billing_address_country = $this->primary_address_country;
        $this->add_address_streets('alt_address_street');
        $newBean->shipping_address_street = $this->alt_address_street;
        $newBean->shipping_address_city = $this->alt_address_city;
        $newBean->shipping_address_state = $this->alt_address_state;
        $newBean->shipping_address_postalcode = $this->alt_address_postalcode;

I’ve added a new field mapping there: but the new mapping does not happen …

Looking further - other files also map address fields of both modules: (a) accounts (‘billing_address_..”) and (b) contacts (primary_address_…”)

Do I need to add my new mapping to some or all of those files also? eg

  • include/generic/SugarWidgets/SugarWidgetSubPanelTopCreateAccountNameButton.php

$additionalFormFields = array();
if (isset($defines[‘focus’]->billing_address_street)) {
$additionalFormFields[‘primary_address_street’] = $defines[‘focus’]->billing_address_street;

  • include/SugarObjects/templates/person/Person.php

if ($newBean instanceof Company) {
$newBean->phone_fax = $this->phone_fax;
$newBean->phone_office = $this->phone_work;
$newBean->phone_alternate = $this->phone_other;
$newBean->email1 = $this->email1;
$this->add_address_streets(‘primary_address_street’);

Some files: include both account and contact address fields, but don’t map them together:

  • include/generic/SugarWidgets/SugarWidgetSubPanelTopCreateAccountNameButton.php

$additionalFormFields = array();
if (isset($defines[‘focus’]->billing_address_street)) {
$additionalFormFields[‘primary_address_street’] = $defines[‘focus’]->billing_address_street;

  • modules/Accounts/AccountFormBase.php
<input type='hidden' name='{$prefix}billing_address_street' value='{$contact->primary_address_street}'>....

Other research:

The boiler-plate text in the popup (“This record currently contains”) is defined as this Label:

  • language/en_us.lang.php: ‘NTC_OPPORTUNITY_REQUIRES_ACCOUNT’

That label is found in these files:

  • include/javascript/sugar_3.js
  • include/javascript/quicksearch.js
  • include/javascript/popup_helper.js
  • include/language/en_us.lang.php
  • jssource/src_files/include/javascript/sugar_3.js
  • jssource/src_files/include/javascript/quicksearch.js
  • jssource/src_files/include/javascript/popup_helper.js

But…. none of those files seems to make a visible change in the PopUp, when adding some RANDOM_TEXT to display. Eg nothing visible changes after R&R, if I change in jssource/src_files/include/javascript/sugar_3.js

4610 else if (confirm(SUGAR.language.get(‘app_strings’, ‘NTC_OVERWRITE_ADDRESS_PHONE_CONFIRM’) + ‘\n\n’ + label_data_str)) {
4611 set_return_basic(popup_reply_data, /\S/);
4612 }

change line 4610 to include ‘my 'RANDOM TEXT’’

else if (confirm(SUGAR.language.get(‘app_strings’, ‘NTC_OVERWRITE_ADDRESS_PHONE_CONFIRM’) + ‘\n\n’ + 'my RANDOM TEXT' + label_data_str)) {

Also nothing happens if I make a similar change in the other 5 JS files above.

Hi Deri!

The jssource files get pulled when you run a Admin / Repairs / Rebuild JS (or rebuild groupings which are aggregated JS files). When that happens the other files are generated, and the generated files are the ones that get sent to the browser for execution.

So it’s common to see two very similar references in two files - one is source, the other is the output of the JS optimization process. If you make changes, you need to do them on the source, so thy don’t get overwritten later.

Then these changes have to reach the browser - hard refresh, clear cache, etc.

But the general thing you’re trying to do seems difficult to me. Your process of finding the ‎NTC_OVERWRITE_ADDRESS_PHONE_CONFIRM‎ label and looking for it was the right approach.

I’m afraid the file where that is being used doesn’t bring me hopes of a quick solution. It seems to be using parts of the HTML to decide which fields to copy - so the real place to fix this is when generating the previous screen, not at the moment of the popup.

Have you tried a workaround with a workflow?

1 Like

Hi pgr
thanks for taking the time to look!

You’re right - a Workflow makes sense: I know you’re the Workflow guru! I’ve used them alot to update fields using information sourced only from the same module.

Is it as easy to pull fields from a related module? Time for me to try that out I guess!

Hello,

I’m using workflows for this as well in several projects.
The question here is the trigger:

Shall the Contact update when a Contact is being saved? Or when an Account is being saved?
There is only a one way update?
Can the Account override an existing value in the Contact field?
If the triggers won’t work out properly, you can use a scheduled workflow to keep the addresses in sync.

3 Likes

Thanks Bastian

Shall the Contact update when a Contact is being saved? Or when an Account is being saved?

Initially just want the first of those.

But I get stuck in Workflow: it seems I can only see 2 fields from the related Account: Account_ID and Account_Name. It’s other fields I need. I’m using ‘Calculated fields’ in this screenshot

But ‘Modify Record’ does not allow me to set a field in Contacts from a field in Accounts: only from one in Contacts: Or am I missing something obvious?!

Try the following on an Account update / trigger:

There, you’d make sure that the contacts city is empty.
If so, you’d be copying the accounts city into the contacts city.
If you have 2 or more contacts matching that criteria for your account, then 2 or more would be updated accordingly.

1 Like

Thanks Bastain: that can PUSH fields from the current module, TO another module. Very nice!
I’m hoping for the reverse:

  • PULL fields from another module, TO the current module

Try that one for a PULL:

1 Like

HI Bastian
that’s perfect -I’ve learnt something! Some how I’d never thought of putting an {R0] field into the formula bar of a Calculated field!
I’d used {P0] alot: so just my blind spot!

Great, glad that it works :slight_smile:

1 Like