HOWTO: Populate enum values from a database table

sugarcrmdevelopers —  April 13, 2011 — 6 Comments

While most of the enum or dropdown fields in Sugar are typically populated by a static list of options, sometimes you’ll want to get the list of options straight from the database. Let’s look at an example from the app to see how we can do this.

The Bugs module has a field named ‘found_in_release’, with the field definition as follows:

The parameter that is important here is ‘function’, where the value of this is a function to call to get the options to display in the UI for this field. The function shouldn’t require any arguments, and should return an associative array with the key as the database value and the value as the display value. For this example, the function looks like this:

You can use this same pattern anywhere you want to create a database driven dropdown.

6 responses to HOWTO: Populate enum values from a database table

  1. 

    where to dfine this function
    mean in which file  ”
    getReleaseDropDown”

  2. 

    and if i want load data of other module for example: I have a products module and categories module and i would want loading my categories names in my enum, where i can define my function? and later where i install my file with this function? thanks

    • 

      ‘function’ => array(‘name’=>’myFunctionName’, ‘returns’=>’html’, ‘include’=>’modules/myModuleOrMyOtherModule/my_file_name.php’),

      my_file_name.php

      this lane is for add a external function in your field. 🙂

Trackbacks and Pingbacks:

  1. Custom Added Dropdown It's Value Come From Other Database - November 19, 2012

    […] […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s