4 min read

A Very Simple Workflow

In our simple workflow we’ll assume that each task is carried out by one person at a time, and that all tasks are done sequentially (i.e. none are done in parallel). So, we’ll look at the PPI Preliminary Investigation which, as you remember, maps to the standard SugarCRM Opportunity. Also, in this example, we’re going to have a different person carrying out each one of the Investigation stages.

Setting up the Process Stages

If you look at SugarCRM then you’ll see that by default none of the stages are related to investigations—they’re all named using standard CRM terms:

Developing a Simple Workflow within SugarCRM

Obviously the first thing to do is to decide what the preliminary investigation stages actually are, and then map these to the SugarCRM stages. You’ll realize that you’ll need to edit the custom/include/langauge/en_us.lang.php file:

$app_list_strings['sales_stage_dom']=array (
'Prospecting' => 'Fact Gathering',
'Qualification' => 'Witness and Subject Location',
'Needs Analysis' => 'Witness and Subject Interviews',
'Value Proposition' => 'Scene Investigation',
'Id. Decision Makers' => 'Financial and background Investigation',
'Perception Analysis' => 'Document and evidence retrieval',
'Proposal/Price Quote' => 'Covert Camera surveillance',
'Negotiation/Review' => 'Wiretapping',
'Closed Won' => 'Full Investigation required',
'Closed Lost' => 'Insufficient Evidence',
);

Don’t forget that you can also do this via Studio. However, once you’ve added your mapping into custom/include/langauge/en_us.lang.php file, and refresh your browser, then you’ll see the new stages:

Developing a Simple Workflow within SugarCRM

Now that our stages are set up we need to know who’ll be carrying out each one.

Deciding Who Does What

In our simple workflow there may not be the need to do anything further. Each person just needs to know who does what next:

For example, once Kurt finishes the ‘Covert Camera surveillance’ stage then he just needs to update the Preliminary Investigation so that the stage is set to ‘Wiretapping’ and the assigned user as ‘dobbsm’.

However, things are rarely as simple as that. It’s much more likely that:

  • Investigations may be based on geographical locations, so that the above table may only apply to investigations based in London. Investigations based in New York follow the same process but with a different set of staff.
  • On Mondays Fran does ‘Witness and Subject Location’ and William does ‘Fact Gathering’.

This means, of course, that we need to be using some businesses rules.

Introducing Business Rules

There are six ‘triggers’ that will cause the logic hooks to fire:

  • after_retrieve
  • before_save
  • before_delete
  • after_delete
  • before_undelete
  • after_undelete

And the logic hooks are stored in custom/modules/<module name>/logic_hook.php, so for ‘Preliminary Inquiries’ this will be custom/modules/Opportunities/logic_hook.php. You’ll also remember, of course, that the logic hook file needs to contain:

  • The priority of the business rule
  • The name of the businesses rule
  • The file containing the business rule
  • The business rule class
  • The business rule function

So, custom/modules/Opportunities/logic_hook.php needs to contain something like:

<?php
#As always ensure that the file can only be accessed through SugarCRM
if(!defined('sugarEntry') || !sugarEntry) die(
'Not A Valid Entry Point');
$hook_array = Array(); #Create an array

$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'ppi_workflow',
'custom/include/ppi_workflow.php',
'ppi_workflow', 'ppi_workflow');
?>

Next we’ll need the file that logic hook will be calling, but to start with this can be very basic—so, custom/include/ppi_workflow.php just needs to contain something like:

<?php
#Define the entry point
if(!defined('sugarEntry') || !sugarEntry) die(
'Not A Valid Entry Point');
#Load any required files
require_once('data/SugarBean.php');
require_once('modules/Opportunities/Opportunity.php');

#Define the class
class ppi_workflow
{
function ppi_workflow (&$bean, $event, $arguments)
{

}
}
?>

With those two files set up as above nothing obvious will change in the operation of SugarCRM—the logic hook will fire, but we haven’t told it to do anything, and so that what we’ll do now.

When the logic hook does run (i.e. when any Primary Investigation is saved) we would want it to:

  • Check to see what stage we’re now at
  • Define the assigned user accordingly

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here