Prefill DD field from related record during record create

For example, we want to prefill a custom field on the Opportunities record with the property of the similar field on the related Accounts record.

We could achieve the same end result using an after_save logic hook but would prefer the flexibility of allowing the user to change the default value during record creation.

We have used the Calculated Value method for non DD field types, but that is not available for DD field types. We also want to store the DD key in the database record rather than the DD label, so want to avoid using an other custom field (eg create a text field and fill it with the label value)

Thanks

Neil

  • Hi Neil Conacher 

    If you want to copy fields from Account to create Opportunity on selecting the Account, then you need to create an extended vardefs in the Opportunities module in order to setup the populate_list in the field account_name. Take a look at modules/Products/vardefs.php (field product_template_name) for reference.

    If you want to automatically copy fields on creating Opportunity from subpanel under Accounts then you need to create an extended vardefs for Accounts and setup the same populate_list in the field opportunities.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi André Lopes

    Thanks for your prompt reply. I'll take a look at that and let you know how I get on

    Neil

  • Hi André Lopes

    I think I understand what you mean. However, I'm unsure of how much of a 'wrapper' I need in the custom file.

    For example, I've copied the section from the account_name field from the module vardefs.php file into my custom file and added the section on populate_list (only 1 field at he moment)

    .. but do I need some additional code to indicate this is part of the Opportunity dictionary ?

    Thanks

    Neil

    <?php

    'account_name' => array(
    'name' => 'account_name',
    'rname' => 'name',
    'id_name' => 'account_id',
    'vname' => 'LBL_ACCOUNT_NAME',
    'type' => 'relate',
    'table' => 'accounts',
    'join_name' => 'accounts',
    'isnull' => true,
    'module' => 'Accounts',
    'dbType' => 'varchar',
    'link' => 'accounts',
    'len' => '255',
    'source' => 'non-db',
    'unified_search' => true,
    'required' => true,
    'importable' => 'required',
    'required' => true,
    'related_field' => array(
    'account_id'
    ),
    'exportable'=> true,
    'export_link_type' => 'one',//relationship type to be used during export
    // custom populate symc_rellead_temp_c from accounts record

    'populate_list' => array(
    'symc_rellead_temp_c' => 'symc_rellead_temp_c',
    ),

    ),

  • The custom file custom/Extension/modules/Opportunities/Ext/Vardefs/foo.php will tell Sugar to compile such change against the stock file. This will provide an upgrade safe customization.

    So that custom file may have a content just like that:

    <?PHP

    $dictionary['Opportunity']['fields']['account_name']['populate_list']['symc_rellead_temp_c'] = 'symc_rellead_temp_c';

    Remember to run Quick Repair and Rebuild from Admin -> Repair

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada