





















































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.
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:
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:
Now that our stages are set up we need to know who'll be carrying out each one.
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:
This means, of course, that we need to be using some businesses rules.
There are six 'triggers' that will cause the logic hooks to fire:
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:
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: