Change relate to dropdown on EditView

Jun 30

Ever wanted to display a relate field as a dropdown list on an EditView?  Here is how you can do it.

Assume you have a custom module that has a relate field to Accounts.  The module will have a field account_name and a field account_id.

In the vardefs.php for your module add the list of options to the account_id field:

  1. 'account_id' =>
  2. 'name' => 'account_id',
  3. ...
  4. 'options' => 'account_list',
  5. ),

Then in the metadata/editviewdefs.php change account_name to account_id and add a type =>’enum’ to it.

  1. 'name' => 'account_id',
  2. ...
  3. 'type' => 'enum',
  4. ),

Then lastly add some code at the top of your modules class file (my_class.php) to create and populate the list.  You can of course add more filters to the where clause to display a subset of related records.

  1. global $db, $app_list_strings, $current_user;
  2. if ($_REQUEST['action'] == 'EditView')
  3. {
  4. $app_list_strings['account_list'] = array(''=>'');
  5. $query = "SELECT, FROM accounts a WHERE a.deleted=0 ORDER BY";
  6. $res = $db->query($query);
  7. while ($row = $db->fetchByAssoc($res))
  8. $app_list_strings['account_list'][$row['id']] = $row['name'];
  9. }

Now do a quick repair on your module to remove the cached vardefs and EditView template and you should see a dropdown list where the select box used to be 🙂

For custom modules built in module builder you should edit the vardefs.php and metadata/editviewdefs.php inside custom/modulebuilder/packages/<package>/modules/<module>/ and the class file in custom/modulebuilder/builds/<package>/SugarModules/modules/<module>/<module>.php.

If the module is a built in module you will have to make the vardefs changes in an extended vardefs file in custom/Extension/modules/<module>/Ext/Vardefs/, change the metadata in custom/modules/<module>/metadata/editviewdefs.php and create the list in an after_retrieve logic hook.



Date/Time in correct format

Jun 30

Here is a simple way to get two variables that contain the current datetime in the current user’s preferred format and in the correct database format.  Use $now_user to set datetime values on SugarBean objects and $now_db to set datetime values in database queries.

  1. global $timedate;
  3. $now_db = $timedate->get_gmt_db_datetime();
  4. $now_user = date($timedate->get_date_time_format());




Jun 27

I am a great believer in tools and one of my most recent additions to my toolbox is WordPress.  Yes it is actually a blog system, but with a little effort and planning it can be a fully fledged content mangement system (“CMS”) for managing a website.

It is a great tool for allowing “ordinary people” to manage and update professional websites.  As an example this entire website is built using WordPress.


Jun 27

SuiteCRM (and SugarCRM it is based on) is an amazing open source customer relations management (“CRM”) system, but it is also much more than that.

Because of it’s open source design it can serve as a great platform for building rich, web-based, database driven, dynamic applications.  I now use it for the admin / back-office portion of nearly all of my projects.

Over the last couple of years I have built quite a few tools to help administrators and developers manage SuiteCRM and SugarCRM installations better.

iPhone App for TicketPros

Jun 27

I have just finished building a WebApp for the iPhone for TicketPros.

The app allows you to browse all events with details and pricing directly on your iPhone.  Since it is a WebApp you can view and install it directly from the TicketPros mobile site.




Improve iPhone voice control

Jun 27

The iPhone now comes with pretty decent voice control, but unfortunately if you are a South African and most of the names you are dialing sounds more Dutch than English, it struggles a bit to recognise the names correctly. As an example, my wife’s name is “Mariette van Niekerk” so the voice control finds Marie, Marion etc., but never Mariette.

So here is a small, quick tip for you.

If you add nicknames to your contacts, you can use the nicknames with voice control for voice dialing. For the example above I added the nickname “Wife” to Mariette’s name in my contacts.  So now I can call her by simply saying “Call wife”.

Not unto the swift…

The race is not to the swift or the battle to the strong, nor does food come to the wise or wealth to the brilliant or favor to the learned; but time and chance happen to them all.
— Ecclesiates 9:11 (NIV)