Logic Hooks and Workflow
Friday, February 8th, 2008Whoa am I tired. It’s been a non-stop whirlwind of shaking hands, answering questions, presentations, and fun. Lots and lots of fun.
At the request of many of you who, I’m posting on the logic hooks and workflow presentations.
Let’s get down to brass tacks - do you know what or where the logic hooks are in SugarCRM? If you don’t, you need to watch this video and bookmark this page.
Workflow is just a glorified logic hook. A lot of the time, I find that I get about 95% of the way with workflow, but it just doesn’t do the last 5% within the workflow UI. However, if I just tried to write a custom logic hook, it would take me longer than if could get that last 5%. Thankfully (wonderfully), Sugar is Open Source, so it’s simple to just split off a workflow and then customize it for the business.
Steps to split a workflow off to a custom logic hook:
Step 1: copy ./include/workflow/WorkFlowHandler.php to ./custom/include/workflow/ (create the directory, it won’t exist)
Step 2: edit the ./custom/include/workflow/WorkFlowHander.php
Step 2a: Rename WorkFlowHandler class to WorkFlowCustomHandler
Step 2b: change all references to the workflow directory to workflow_cstm
Step 2c: change all references to $target_class to $target_class = $focus->module_dir.”_workflow_cstm”;
Step 3: Edit the logic_hook.php file in the target module (ie: ./custom/modules/Accounts/logic_hook.php)
Step 3a: Add another $hook_array pointing to (./custom/include/workflow/WorkFlowHandler.php).
Step 3b: Make sure the $hooks_array calls the new WorkFlowCustomHandler class (see the video, if you’re lost right now)
Step 4: Copy the workflow directory to workflow_cstm, (ie: ./custom/modules/Accounts/workflow_cstm
Step 5: Change all references to the includes for the workflow directory to workflow_cstm directory. For example:
include('custom/modules/Accounts/workflow_cstm/triggers_arrays.php);
include('custom/modules/Accounts/workflow_cstm/action_arrays.php;
Step 6: Alter workflow.php to your desired behavior (ie: ./custom/modules/Accounts/workflow_cstm/workflow.php);
That’s it folks. Workflow just got split off. Word to the wise though - DELETE the workflow in the UI. Every time the definition saves, it will save the workflow.php. Best to delete it and log it elsewhere that you’ve created a logic_hook.
So you have all the power of workflow, plus more. And - it’s upgrade safe!