Quantcast
Channel: Veon Consulting
Viewing all articles
Browse latest Browse all 166

Schedulers and Cron Job in SugarCRM

$
0
0

Schedulers are scripts that run periodically and execute a predefined business logic. They are also called batch jobs and are often scheduled based on business rules and priorities. Schedulers in SugarCRM help in automating the business process or set of custom tasks and is a very useful tool for SugarCRM developers

Banner SugarCRM Services link landing page

Example of a SugarCRM scheduler – Consider an electronics company which promises its customers a free service after one year of product purchase. To deliver this promise, an automation is needed so that followup can be done in timely fashion. So, the company has to track all the customer purchase data and based on the order history. A SugarCRM scheduler can help read the purchase history, create tasks automatically within the CRM and assign it to the correct sales representative so that it starts appearing in his / her dashboard.


Predefined SugarCRM Schedulers / Batch Jobs 

If you thought that all the jobs are custom made, you are wrong. SugarCRM has quite a few standard jobs which ensure healthy functioning of the application.  I am listing few of the jobs which are available out of the box within SugarCRM.

  • Advanced Workflow Scheduled Job – This Job is run for the processes associated with Advanced workflow. 
  • Check Inbound Mailboxes This job checks the inbound mails of the inbound connections in SugarCRM. 
  • Clean Jobs Queue –  This job is used to clean the scheduler logs. At first, the scheduler record log will be soft-deleted (hiding from Sugar user interface) and then the record is hard deleted (remove completely from database). Usually soft delete is done after 7 days and hard delete is done after 21 days.  
  • Elasticsearch Queue SchedulerNew, updated and deleted records can be updated to elastic search using this scheduler.
  • Prune Database on 1st of MonthWhile deleting the records, Sugar soft deletes the records. These records are hard deleted and are removing completed from the CRM.
  • Prune Old Record Lists This job is used to clean logs entered while performing export action. 
  • Prune Tracker Tables This job is used to clean tracker tables as the data in the tracker tables is filled for each action in the CRM. 
  • Remove Temporary Files Sugar stores few files in cache and uploads directory. These files are removed with this scheduler on a daily basis. 
  • Remove Temporary PDF Files The temporary PDF files that are stored in the cache directory while performing Reports, Quotes generation, etc are removed with this scheduler. 
  • Run Email Reminder Notifications This scheduler is used to send Email reminders for Meetings, Calls, and Tasks. 
  • Run Nightly Mass Email CampaignsThis scheduler is used to run email campaigns at night. 
  • Run Report Generation Scheduled Tasks This job is used to run the scheduled reports and email the reports to the respective users assigned in CRM.

Other than these default jobs, organizations may need to have a custom process that needs to run on a frequency basis; like providing reminders, executing jobs for maintaining proper management. 


Creation of Custom SugarCRM Scheduler 

Having understood the concept and the use of SugarCRM scheduler, let us look at how to create a custom one afresh. This tutorial requires that you understand PHP and SugarCRM architecture. If you do not, you might want to contact us for a free no-obligation quote for your SugarCRM needs.  

Steps to create a scheduler 

  • Create a file at <instance>/custom/Extension/modules/Schedulers/Ext/Language/<language_key>.<name>.php 
    • Language key – en_us, en_uk, etc 
    • Name – Job name
      Eg: instance>/custom/Extension/modules/Schedulers/Ext/Language/en_us.free_service_tasks.php 
    • The label key is the function name in caps.

<?php
$mod_strings['LBL_FREE_SERVICE_TASKS'] = 'Free Service Task'

  • Create a function with the job name that clarifies on the purpose of the job in <instance>/custom/Extension/modules/Schedulers/Ext/ScheduledTasks/<function_name>.php 
    • Function_name – Name of the PHP function

<?php 
  
array_push($job_strings, 'free_service_tasks'); 
function free_service_tasks() 
{ 
    // write logic here to create task based on one year purchase of 	
the product 
    // return true for completed 
    return true; 
}

  •     Do a quick repair and rebuild.  
  •     Go to Admin -> Scheduler -> Create Scheduler.
  •     Enter the Job Name, status, and interval for the script to execute.
  •     Select the created job from the Job Dropdown. 

 Below is the screenshot for reference.

Screenshot of Custom Schedulers Edit view

  •     Save the Job and wait for the job to execute.
  •     And check in Job log in the detail view of the scheduler to verify whether the job is executed or not.

Screenshot of Custom Schedulers Detail view

Setting up the CRON for the scheduler jobs

Now that we have written the script, let us look at how to make it automatically run at the specified interval. There are two different approaches based on which operating system you are using. I am listing down the steps for both Unix and Linux environments below.

In Unix 

Open the terminal and Enter the command

usr@env:~$ crontab -e

Place the following command in the file and save the file

* * * * * cd /var/www/sugar123; php -f cron.php > /dev/null 2>&1

**sugar123 is the instance folder name of the SugarCRM

In Windows 

  • Go to Admin -> Scheduler 
  • At the bottom of the page find the code to put in the batch file for Cron job to run. 
  • Create a file .bat and insert the code. Save the file. 
  • A scheduler is set up successfully. Check the logs to verify the scheduler status.

Advantages of SugarCRM schedulers

As you can imagine, schedulers within SugarCRM has a strong business case. It takes out the monotony of doing repeated stuff at regular interval in a manual fashion. They help the process to run in the background without any effect on the user interface and the humans, simplifying the run of the process and increasing the effective use of the hardware resources available.

At a broad level, following are the advantages of using SugarCRM schedulers. 

  • The business process can be automated. 
  • Less follow up for the Customer/Lead. 
  • High productivity and efficiency of the employees. 
  • Scheduled Reports for a better understanding of the performance of the organization. 
  • Improvement in financial planning by having reminders for the regular/term-based payments. 
  • Better project management workflows

Evaluating SugarCRM for your business – We can help

Reach out to us so that we can assess and plan a road-map for your CRM implementation. Let’s build a system, which you will use for years to come.

Contact us for a free assessment


Viewing all articles
Browse latest Browse all 166

Trending Articles