Mon 8 Apr 2013
How to add programmatically new scheduler job in SugarCRM
Posted by Marian Dobre under SugarCRM1 Comment
In SugarCRM you can add Schedulers to execute repetitive tasks (like CRONs in LINUX). By default, SugarCRM comes with a list of predefined jobs, that can be setup via Admin -> Scheduler.
But if you want to implement a custom job and to be accessible in this module, you must do the following. The solution is implemented in an upgrade safe manner.
1. In custom/modules/Schedulers/ create a file named _AddJobsHere.php
// this file is actually included at the end of /modules/Schedulers/_AddJobsHere.php
//You can take a look on that file for more clarification
//create a new registered job
$job_strings[] = 'customJob';
function customJob(){
//this is where you put the custom code
}
?>
2. Create the language file for new job: custom/modules/Schedulers/language/en_us.lang.php . If the path doesn’t exists you must create the directory structure. $mod_strings['LBL_CUSTOMJOB'] = 'This string will appear in dropdown list of job field when you create or edit a new job in Sheduler '; ?>
3. Perform a Quick repair and rebuild from Admin -> Repair area.
After that, in Amin -> Scheduler, if you click Create (or Edit an existing item), you will see that a new value appear corresponding “Job” dropdown list.
That’s all folks!
May 31st, 2013 at 6:43 pm
Great write up Marian! I always love seeing people share their SugarCRM knowledge.
The one thing to be aware of is that there are some installable modules out there that overwrite the same _AddJobsHere.php file. Which means that your changes could potentially be blown away. Using _AddJobsHere.php is just fine for your own install. Just be careful to check before installing a module to see if they use the same file. What they should be doing is adding the scheduler job with the Ext framework as described here: https://www.sugaroutfitters.com/blog/how-to-add-scheduler-tasks-in-the-manifest
This method also works well for managing your own instance and helps eliminate one potential nightmare.
Keep on writing! You’re covering some cool topics.
Best,
Jason