Create Contact - Don't autocomplete phone number when creating new contact and select account

When I create a contact, I can assign an account to it. I can select the account in the associated autocomplete field or the picker (pop-up). Once I have selected an account, the address and the phone number (phone_office > phone_work) are automatically imported.

How can I prevent the phone number from being copied automatically?

I tried it with a logic hook in Contacts - but there is no suitable event, because the “Account Module” populates the phone number.

With a logic hook in Accounts I can delete the phone number “on the fly” (see below), but it is then no longer displayed in other modules (e.g. Accounts) due to the selected event. Events such as “before_save” and “after_retrieve” did not work.

Actually, the problem sounds pretty simple. But I just can’t get it solved.

How can I “tell” the logic hook that we are currently on the Create Contact page?
Or can someone point me in the right direction on how to solve the problem using javascript?

custom/Extension/modules/Accounts/Ext/Logichooks/AccountHooks.php
$hook_array['process_record'][] = Array(1, 'Stop autocomplete phone', 'custom/modules/Accounts/AccountLogicHook.php','AccountLogicHook', 'stopAutocompletePhone');

custom/modules/Accounts/AccountLogicHook.php

    public function stopAutocompletePhone($bean, $event, $arguments)
    {
        $GLOBALS['log']->fatal("Entering my hook stopAutocompletePhone");

        if ($bean->phone_office) {
                 $GLOBALS['log']->fatal("Phone: " . $bean->phone_office);
         }
         $bean->phone_office = " ";   // Working, but not only on this specific page
          //  $bean->save();  // Not necessary
        
       // Not working
        if ($bean->parent_type == 'Contacts') {
            $GLOBALS['log']->fatal($bean->parent_type);
            $bean->phone_office = " ";
            $bean->save();
        }
    }

Any help is greatly appreciated. Thank you!

I suggest first trying to find out exactly where in the core code this is happening, maybe you can work through this list:

I would bet it is either that Person.pho or one of the quickcreates, if that’s the screen you’re on.

So, first, try to fix your issue by commenting out the line in core code, just to see where it is happening. Then tell me where it is and I will try to guide you to make the customization outside core (upgrade-safe), probably it will be by sub-classing the view and redefining the relevant function.

Thank you for your answer! I’ve worked my way through the files and mostly commented out the relevant fields, but the phone number is still passed as soon as you select an account.

I suspect that the Contact module is left out completely and the “phone_work” field is filled via the Acccount module using javascript.

Unfortunately, I haven’t made any progress yet. If you have another idea, please share! I will look into this further tomorrow.

Yes, it could be a bit of Javascript, but let me just try one more guess, this line here:

Maybe you can try removing the entire additional_fields part, or even the entire display_params.

Don’t forget to Quick Repair and Rebuild before testing.

Wow, it’s solved! I already tried your solution, but I made a stupid mistake - I temporarily edited the file in modules/Contacts without realizing that it is already overwritten in customs/modules/Contacts. So it didn’t work of course. Oh man …

So I solved it by just editing this line:
'phone_office' => 'phone_work',

New:
'phone_office' => '',

Thank you very much for sticking with it and thus drawing my attention to my mistake.

1 Like