Create address field with code

Hello all,

Is there an easy and upgrade safe way to create, from code (custom/Extension etc.) , an address field (so 5 db fields but a single field from the studio > layout section) ?

Kind regards, 

Fred

  • Any reason to do not create such field through Studio?

    The field type "Address" do the job. On creating a field from this field type SugarCRM will create those 5 fields.

    In case you REALLY need to create from the scratch then this code may help you:

    'billing_address_street' =>
    array (
    'name' => 'billing_address_street',
    'vname' => 'LBL_BILLING_ADDRESS_STREET',
    'type' => 'text',
    'dbType' => 'varchar',
    'len' => '150',
    'comment' => 'The street address used for billing address',
    'group' => 'billing_address',
    'group_label' => 'LBL_BILLING_ADDRESS',
    'merge_filter' => 'disabled',
    'duplicate_on_record_copy' => 'always',
    'full_text_search' =>
    array (
    'enabled' => true,
    'boost' => '0.35',
    'searchable' => true,
    ),
    'audited' => true,
    'massupdate' => false,
    'comments' => 'The street address used for billing address',
    'duplicate_merge' => 'enabled',
    'duplicate_merge_dom_value' => '1',
    'calculated' => false,
    'rows' => '4',
    'cols' => '20',
    ),
    'billing_address_city' =>
    array (
    'name' => 'billing_address_city',
    'vname' => 'LBL_BILLING_ADDRESS_CITY',
    'type' => 'varchar',
    'len' => '100',
    'comment' => 'The city used for billing address',
    'group' => 'billing_address',
    'merge_filter' => 'disabled',
    'duplicate_on_record_copy' => 'always',
    'audited' => true,
    'massupdate' => false,
    'comments' => 'The city used for billing address',
    'duplicate_merge' => 'enabled',
    'duplicate_merge_dom_value' => '1',
    'full_text_search' =>
    array (
    'enabled' => '0',
    'boost' => '1',
    'searchable' => false,
    ),
    'calculated' => false,
    ),
    'billing_address_state' =>
    array (
    'name' => 'billing_address_state',
    'vname' => 'LBL_BILLING_ADDRESS_STATE',
    'type' => 'varchar',
    'len' => '100',
    'group' => 'billing_address',
    'comment' => 'The state used for billing address',
    'merge_filter' => 'disabled',
    'duplicate_on_record_copy' => 'always',
    'audited' => true,
    'massupdate' => false,
    'comments' => 'The state used for billing address',
    'duplicate_merge' => 'enabled',
    'duplicate_merge_dom_value' => '1',
    'full_text_search' =>
    array (
    'enabled' => '0',
    'boost' => '1',
    'searchable' => false,
    ),
    'calculated' => false,
    ),
    'billing_address_postalcode' =>
    array (
    'name' => 'billing_address_postalcode',
    'vname' => 'LBL_BILLING_ADDRESS_POSTALCODE',
    'type' => 'varchar',
    'len' => '20',
    'group' => 'billing_address',
    'comment' => 'The postal code used for billing address',
    'merge_filter' => 'disabled',
    'duplicate_on_record_copy' => 'always',
    'audited' => true,
    'massupdate' => false,
    'comments' => 'The postal code used for billing address',
    'duplicate_merge' => 'enabled',
    'duplicate_merge_dom_value' => '1',
    'full_text_search' =>
    array (
    'enabled' => '0',
    'boost' => '1',
    'searchable' => false,
    ),
    'calculated' => false,
    ),
    'billing_address_country' =>
    array (
    'name' => 'billing_address_country',
    'vname' => 'LBL_BILLING_ADDRESS_COUNTRY',
    'type' => 'varchar',
    'group' => 'billing_address',
    'comment' => 'The country used for the billing address',
    'merge_filter' => 'disabled',
    'duplicate_on_record_copy' => 'always',
    'audited' => true,
    'massupdate' => false,
    'comments' => 'The country used for the billing address',
    'duplicate_merge' => 'enabled',
    'duplicate_merge_dom_value' => '1',
    'full_text_search' =>
    array (
    'enabled' => '0',
    'boost' => '1',
    'searchable' => false,
    ),
    'calculated' => false,
    ),

    Set up equivalent fields in an Extension Vardefs and make sure all fields has the attribute "group" whose value is the very same in all of them.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hello André Lopes,

    Thank you for this answer.

    We create fields through code to get an easier way to track (GIT) and deploy fields between multiple environments.

    The problem is that, even with the code you provided and if the field in not billing_address or shipping_address or any core name field for the address (for instance, we want to add a communication address to the account), Sugar doesn't suggest a group fieldset from the studio but several fields.

    And if you create an address field from the builder or the studio, you get the same issue.

    So my question was : how Sugar know that those fields must be handled, from the studio, as a fieldset.

    Fred