Button Field - How to embed the "definition" in a vardef file instead of partial DB storage

Hi Guys,

I have a quick question : do you know how to store in a vardef file the FULL definition of a button field (instead of the current storage when created from the studio with partial storage in DB table) ?

The purpose of this request is to easily deploy custom buttons for our customers and also be able to track the code with GIT.

Many thanks,

Fred

  • Hi,

    we figured how to do it, so if some of you are interested, contact me.

    Regards

    Fred

  • Hi  ,

    today we do this that way

    1 ) create a sugarfield_the_name_of_my_button.php in

    custom/Extension/modules/<MODULE_NAME>/Ext/Vardefs

    2) include a basic definition for the field

    <?php
    // this file was created by dotBase the ...
    $dictionary['MODULE_NAME']['fields']['the_name_of_my_button']['name']='the_name_of_my_button';
    $dictionary['MODULE_NAME']['fields']['the_name_of_my_button']['vname']='LBL_THE_NAME_OF_MY_BUTTON';
    $dictionary['MODULE_NAME']['fields']['the_name_of_my_button']['type']='actionbutton';
    $dictionary['MODULE_NAME']['fields']['the_name_of_my_button']['options']='';
    $dictionary['MODULE_NAME']['fields']['the_name_of_my_button']['dbType']='text';

    3) launch a quick repair and run the query to align DB and code

    4) finish the button configuration from studio, so all the settings will be stored inside the sugarfield_xxx instead of fields_metadata

    OF COURSE, we are aware that this field is not seen as a custom field and so created in the main table.

    But this is a most convenient way for us to track code customisation / versionning using GIT, even more with mutliple environnement (DEV, STAGING, PROD etc.).

    Hope it helps,

    Fred

  •  interesting solution, thanks for sharing.. 

    SugarCRM | Principal Developer Advocate

  • If you create such a button in studio you get the full vardef description in cache/modules/MODULE/MODULEvardefs.php. As an example I created  button in Accounts which results in the following vardef code:

        'button1_c' => 
        array (
          'labelValue' => 'Button1',
          'required' => false,
          'readonly' => true,
          'source' => 'non-db',
          'name' => 'button1_c',
          'vname' => 'LBL_BUTTON1',
          'type' => 'actionbutton',
          'massupdate' => false,
          'hidemassupdate' => false,
          'no_default' => false,
          'comments' => 'Comment for Button 1',
          'help' => 'Help for Button 1',
          'importable' => 'true',
          'duplicate_merge' => 'enabled',
          'duplicate_merge_dom_value' => 1,
          'audited' => false,
          'reportable' => true,
          'unified_search' => false,
          'merge_filter' => 'disabled',
          'pii' => false,
          'calculated' => false,
          'size' => 50,
          'studio' => 
          array (
            'editField' => true,
            'recordview' => true,
            'previewview' => true,
            'recorddashletview' => true,
            'listview' => false,
            'wirelesseditview' => true,
            'wirelesslistview' => false,
            'wirelessdetailview' => true,
            'wireless_basic_search' => false,
            'wireless_advanced_search' => false,
          ),
          'dbType' => 'text',
          'options' => '{"settings":{"type":"YnV0dG9u","size":"ZGVmYXVsdA==","showFieldLabel":false,"showInRecordHeader":false,"hideOnEdit":false},"actionMenu":{"orderNumber":1,"listView":true,"recordView":false,"recordViewDashlet":false,"subpanels":true},"buttons":{"0cbbfd0d-7cd1-419b-ac83-1d23b4f40aff":{"active":true,"buttonId":"MGNiYmZkMGQtN2NkMS00MTliLWFjODMtMWQyM2I0ZjQwYWZm","orderNumber":0,"properties":{"label":"Q1JFQVRF","description":"VG9vbHRpcCB0ZWN0","showLabel":true,"showIcon":true,"colorScheme":"cHJpbWFyeQ==","icon":"c2ljb24tZm9sZGVyLW9wZW4=","isDependent":false,"stopOnError":false,"formula":""},"actions":{"7ab2e8b4-eb24-48bf-a751-354025647579":{"actionType":"Y3JlYXRlLXJlY29yZA==","orderNumber":0,"properties":{"attributes":{},"parentAttributes":{},"module":"QWNjb3VudHM=","link":"","mustLinkRecord":false,"copyFromParent":true,"autoCreate":false}}}}}}',
          'id' => 'e648add0-4b3f-11ee-a848-54ee7593936c',
          'custom_module' => 'Accounts',
        ),

    Most complicated part is the options field which is generated by the QR&R from the DB definition.

    In a development environment you have access to the cache folder and you can extract this definition form the vardef file to include it in custom/Extension/modules/MODULEs/Ext/Vardefs/ folder and by this in GIT.