Format Date according to User’s Date Format.


Quite recently, I faced an issue wherein I have to push some calculated date(based on some algo) to the date field on EditView of a custom module.

My custom function calculated date in dd/mm/yyyy format but the user can have any possible date formats defined by SugarCRM.

Before pushing my calculated date i need to format this date according to user’s settings.

I came through this intelligent post from Johndope

I did little modifications in the code and hurray it solved my problem.

global $current_user; // Instantiate the TimeDate Class
$timeDate = new TimeDate();
$sampleDate = '2014-08-28'; // Sample date.
// Call the function
$FormatedDate = $timeDate->to_display_date($sampleDate, true, true, $current_user);
echo "Date->".$FormatedDate;
//If you want to get time too use the following code.
$sampleDateTime = '2014-08-28 08:00:00'; // Sample date.
// Call the function
$FormatedDateTime = $timeDate->to_display_date_time($sampleDateTime, true, true, $current_user);
echo "DateTime->".$FormatedDateTime;




HOWTO: Using the bean instead of SQL all the time.

Sugar Developer Blog - SugarCRM

Editor’s Note: This has become one of the most popular posts on the developer blog, so thank you everyone for your interest.

Do note that if you are using Sugar 6.3 or later, check out this post for an even easier way to load beans.

I had one of our community members who likes to “keep us honest” call me out the other day on Twitter…

And he was referring to a post we did where we did some raw SQL queries in the code example. I’ve updated the code examples since then to be correct. And Jeff don’t worry, as you rightfully so called us out on slipping a bit from our normal quality here :-).

But to start off, why is this important? Here’s a few reasons…

  • Code portability. Even the most conservative SQL code can have issues on a DB you haven’t tested you add-on against. If…

View original post 899 more words

SugarCRM Cookbook – SugarQuery – The Basics

Sugar Developer Blog - SugarCRM

You have found yourself in a bind, and you need to query the database directly. There is no other recourse than to write a query to get the data you need. This cookbook entry is going to give you some examples on how to use our new SugarQuery API instead of direct SQL.

1. What is SugarQuery?

SugarQuery is a SQL query builder for retrieving data directly from the database.  It is used extensively within the core of the application.  For instance, the FilterAPI uses it.

It uses a bean, the beans relationships, and visibility models to build a SQL query that can be used to retrieve data.

2. The Basics

SugarQuery has a very simple interface for building queries.

The basic methods you will need to create a query are:

  • select($fields) – accepts an array of fields you would like to select
  • from($bean) – validates the query against a SugarBean at generation
  • where()…

View original post 292 more words

HOWTO: Add your own admin panels

Sugar Developer Blog - SugarCRM

Many of you who develop modules on SugarForge or for your own Sugar instance often find the need to add in administration functionality for it. This maybe use to control features or functionality of the module, or perhaps define some defaults that are used in the module. Fortunately, the ability to add these panels as a part of the existing admin section is a very easy and upgrade-safe task.

You can define new admin items in the custom/Extension/modules/Administration/Ext/Administration/ directory, creating a new .php file in that directory to hold the admin items. There are two parts to defining this; in the first part we will define the actual admin panels we will be adding.

$admin_options_defs=array(); $admin_options_defs['MODULENAME']['ADMINPANEL1']=array(        'MODULENAME',         'LBL_ADMINPANEL1_TITLE',         'LBL_ADMINPANEL1_DESC',         './index.php?module=MODULENAME&action=ADMINPANEL1VIEW' ); $admin_options_defs['MODULENAME']['ADMINPANEL2']=array(        'MODULENAME',         'LBL_ADMINPANEL2_TITLE',         'LBL_ADMINPANEL2_DESC'…

View original post 75 more words

HOWTO: Create a Flex Relate for other modules

Sugar Developer Blog - SugarCRM

You may recall seeing this field in the various activity modules in Sugar:

This is what’s known as the “Flex Relate” field, which allows you to relate a record to one in a different module that you specify. This allows you to create a relationship where the target entity is flexible, which allows you to represent all sorts of business logic clearly. A great example of this the various activity entities in the app ( Calls, Meetings, Tasks ), which make it so you can relate the activity to one of many different record types.

The only downside of this field, is there’s no good way to build it using Module Builder or Studio ( or least in a very useful way ). However, it’s a pretty easy code customization you can do which is upgrade-safe. Let’s look at how.

We’ll assume we made a new custom module via Module…

View original post 167 more words

Run Scheduler without accessing Cron.

Cronless Job


To run a Scheduler you need to add an entry in cron.Many times hosting provider limits cron usage and without an entry in cron the Scheduler wont run.

However there is an easier way out as show in the below steps.

If you are using SugarCRM you will have to follow step 3 else the first two steps will suffice.


  1. Setup a cronjob at a free cron provider like or .
  2. Point them to the cron.php to your SugarCRM directory. For example http://yourdomain/SugarCRM/cron.php
  3. Comment the code as shown below in cron.php and save it. You dont need to this if you are not using SugarCRM.
                       //$sapi_type = php_sapi_name();
                     //if (substr($sapi_type, 0, 3) != 'cli') {
                        //    sugar_die("cron.php is CLI only.");


Now when the cron.php is visited on scheduled time it will trigger the Scheduler.

Isn’t it an awesome way to execute the Scheduler.Thanks to the cron providers.





Remove Create Action button.

At times you will have a requirement to remove Create or any other action from menu of a particular module.

My module requires only to list the data and not allow creation or import of data.This can be simply achieved simply by changing some files of the modules.You just need to have access to the files of the module.

To remove the create and import action from the menu do the following :

Open Menu.php of the module and just comment or remove the actions you dont want.


Here you may see that the add and import actions have been removed from the menu and the only available option is list action.

Though the user can access the EditView by passing required parameters in the URL.

Eg : localhost/sugarcrm/index.php?module={module}&action=EditView.

If you want to disable or disallow such an access follow below steps.

  1. Create view.edit.php at custom/module/{module}/views/view.edit.php
  2. Write the following code therein.
  class User__User_ActivityViewEdit extends ViewEdit{
    function display(){
              sugar_die('You cannot create new records here, sorry'); 

Now if the user still tries to access the edit view below screen will be displayed.

editview disabled
EditView Disabled























Disable Edit Link from ListView

SugarCRM module’s List View comes with default options like an edit view link and  a checkbox besides it.

Many times users feels a need to hide the link and/or checkbox.However this cannot be done from SugarCRM admin panel,but you can do it if you have access to its files.

Create a file called view.list.php at custom/modules/{module}/views/view.list.php and write the code below.If you have the file view.list.php at
modules/{module}/views/ copy it to custom/modules/{module}/views else create a new one in custom.

Write the below code therein.

class {module}ViewList extends ViewList
    function {module}ViewList()
    function Display()
        $this->lv->quickViewLinks = false; // Removes Edit View Link
        $this->lv->multiSelect = false; //    Removes Check Box     







Test your addon on SugarCRM On-Demand.


Sugar On-Demand comes with a lot of module loader restrictions which might make your module installation a complete failure.I faced the same issue when installing the addon I created and installing it on Sugar On-Demand.

You have created a great module but will it work on Sugar On-Demand is big damn question.

Thankfully you can test this on your local SugarCRM environment and save the programming and support time later.

You just need to set package scanner  to be true.

To do this simply add the following line to your config_override.php file.

$sugar_config['moduleInstaller']['packageScan'] = true;


Now when you you install the package it will work same as it will do it on Sugar On-Demand version.

It will then return all the issues found in the package that makes it incompatible with On-Demand version.





Change SugarCRM Admin Password with SQL

Reset Password

Suppose you or someone else have installed SugarCRM ,but you are not able to get  its access , the only wayout is to change/reset the admin password via SQL.

Get into the respective database and find table users.Firstly you will have to find the active admin account.

The active admin account is one whose is_admin column is set to 1 and the column status is set to  active .

The below sql query displays all active admin users.

SELECT user_name FROM users WHERE is_admin = '1' AND status = 'Active';

The password is simply a md5 hash, therefore you can set it to any value you like via:

UPDATE users SET user_hash = MD5('PASSWORD') WHERE user_name = 'USERNAME';