Results 1 to 2 of 2

Thread: Custom field options for stock field types, with code contained to custom/ ?

  1. #1
    przemoli Guest

    Default Custom field options for stock field types, with code contained to custom/ ?

    Anyone know if its possible (with tips apreciated) to create custom field OPTIONS (like required, merging duplicates, etc), in a way that would not require modifying stock SugarCRM (prefer to have all changes contained to custom/).

    (And Yes I would (possibly) need that option for all fields in CRM - and custom code coupled with such field option)


    If not possible, than what other options there are for modifying all the fields in system (yes, constrains for fields are primary use case here).

  2. #2
    Francescas's Avatar
    Francescas is offline Sugar Community Member
    Join Date
    Dec 2011
    Location
    Colorado
    Posts
    508

    Default Re: Custom field options for stock field types, with code contained to custom/ ?

    Quote Originally Posted by przemoli View Post
    Anyone know if its possible (with tips apreciated) to create custom field OPTIONS (like required, merging duplicates, etc), in a way that would not require modifying stock SugarCRM (prefer to have all changes contained to custom/).

    (And Yes I would (possibly) need that option for all fields in CRM - and custom code coupled with such field option)


    If not possible, than what other options there are for modifying all the fields in system (yes, constrains for fields are primary use case here).
    Yes, you put those changes in:
    Code:
     custom/Extension/modules/<module name>/Ext/Vardefs

    Duplicate merge enable(1)/disable(0)
    PHP Code:
    $dictionary['<your module>']['fields']['<your field>']['duplicate_merge_dom_value']=0
    Required (true)/ Not required (false)
    PHP Code:
    $dictionary['<your module>']['fields']['<your field>']['required']=false
    Other things you can do…

    some examples of what I did in the Cases module, these are all in
    Code:
    custom/Extension/modules/Cases/Ext/Vardefs/vardef.ext.php
    in my case (you can name the file anything you want as long as it's in the right directory).

    Enable date range searches on a custom date field. This one is case_assigned_date_c in module Cases :
    PHP Code:
    $dictionary['Case']['fields']['case_assigned_date_c']['enable_range_search'] = true;
    $dictionary['Case']['fields']['case_assigned_date_c']['options'] = 'date_range_search_dom'
    Show the field for case_production_system_c only if the case_support_level_c dropdown is 'Enterprise'
    PHP Code:
    $dictionary['Case']['fields']['case_production_system_c']['dependency'] = 'equal($case_support_level_c,"Enterprise")'
    Dependent dropdowns, dropdown fieldA_c determines what options are shown in fieldB_c
    on the left are the values for fieldA, on the right the corresponding options that should show in B
    (I made up some senseless fields/values for the sake of the example)
    NOTE: use Database values, not user values from your language files for this to work.
    PHP Code:
    $dictionary['Case']['fields']['color_c']['visibility_grid'] = array(
       
    'trigger' => 'type_of_color_c',
       
    'values' => array(
            
    'PrimaryColors'=>array('yellow','blue','red'),
            
    'AllColors'=>array('yellow''blue''red''purple','magenta'),
            
    'NonPrimaryColors'=>array('purple','magenta'),
       )
    ); 
    You can also make conditional required fields in the Dependencies directory in Extensions, for example in my Cases module
    custom/Extension/modules/Cases/Ext/Dependencies/deps.ext.php
    (again, name the file what you wish)
    if case_requesting_org_c (the dropdown) is Reseller, then make case_reseller_c required.

    PHP Code:
    $dependencies['Cases']['required_reseller'] = array(
            
    'hooks' => array("edit"),
            
    'trigger' => 'true',
            
    'triggerFields' => array('case_requesting_org_c'),
            
    'onload' => true,
            
    //Actions is a list of actions to fire when the trigger is true
            
    'actions' => array(
                    array(
                            
    'name' => 'SetRequired',
                            
    //The parameters passed in will depend on the action type set in 'name'
                            
    'params' => array(
                                    
    'target' => 'case_reseller_c',
                                    
    'label'  => 'case_reseller_c_label',
                                    
    'value' => 'equal($case_requesting_org_c, "Reseller")',
                            ),
                    ),
            ),
    ); 
    NB: for all changes in custom/Extensions you must repair rebuild before they take effect.
    You will see the code is copied in custom/modules/<your module>/Ext/
    NEVER edit anything in custom/modules/<your module>/Ext/
    And if you use version control I would avoid adding the custom/modules/<your module>/Ext directories altogether

    Sometimes I have problems when I repair/rebuild especially when copying files between environments from production to test.
    I delete all the Ext directories under the custom/modules/<module name> and repeat the repair rebuild to get new clean files in there and it helps.

    HTH.
    Francesca
    Last edited by Francescas; 2014-02-13 at 04:00 PM.
    Francesca
    =========
    SugarCRM Professional 6.5.15
    Linux
    Apache
    MySql
    PhP

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 2012-01-24, 11:55 AM
  2. Replies: 2
    Last Post: 2011-05-16, 02:50 PM
  3. custom function call from custom code field in metadata
    By josh.sweeney in forum Developer Help
    Replies: 9
    Last Post: 2010-02-09, 09:23 PM
  4. Custom code for a custom field in default module
    By kodikarthi in forum Developer Help
    Replies: 7
    Last Post: 2009-02-19, 04:25 PM
  5. Replies: 1
    Last Post: 2007-08-28, 11:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •