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;



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     







Make custom EditView work for Quickcreate.


In this article I will show you how you can make your Custom EditView of any module also work for quickcreate via subpanels.

This took me way too long to figure out as well and I am happy to share the quite easy answer with you!

In your custom view.edit.php file add the following line inside the __construct() method:

$this->useForSubpanel = true;

The above code will make custom edit view functions to also work for quickcreate.


How to create a Custom Scheduler in SugarCRM

SugarCRM comes with its pre-defined Schedulers which you can set from Admin->Schedulers.Schedulers comes into place when you want to perform a recurring job .It is just as Linux Crontab.

CRM Scheduler

To create a custom scheduler you can use the Ext framework of Sugarcrm.

STEP 1 : Create a file MyJob.php in custom/Extension/modules/Schedulers/Ext/ScheduledTasks/ with the following code therein

$job_strings[] = 'MyJob';
 function MyJob(){
 //this is where you put the custom code

STEP 2 : The next step is to create a language file for our custom scheduler.Create en_us.MyJob.php in custom/Extension/modules/Schedulers/Ext/Language/ with the following code

$mod_strings['LBL_MYJOB'] = 'My Custom Job';

STEP 3 : Do a Quick Repair and Rebuild . Your custom scheduler will now be available in the Scheduler dropdown list.After which you can set its execution interval.


Creating custom Scheduler via _AddJobsHere.php is not recommended.Its a shared file and any other customizations can simply override your scheduler.The safest way is to use the Ext framework discussed above.However you will have to use _AddJobsHere file for Sugar Version less than 6.4.