Logic Hooks and Workflow

sugarcrmdevelopers —  February 8, 2008 — 5 Comments

Whoa 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!

5 responses to Logic Hooks and Workflow

  1. 

    Matt, nice post. I’d only add a reference to Max Blackmer’s timeless workflow hook in SugarForge: http://www.sugarforge.org/projects/deassign/

    It performs the opposite of the notification; when a person “loses” a record because it is assigned to someone else, this workflow steps in and notifies that person that the record is no longer assigned to him/her.

    Very useful, and serves as a great (and simple) example.

    Andy

  2. 

    Matt, nice post. I’d only add a reference to Max Blackmer’s timeless workflow hook in SugarForge: http://www.sugarforge.org/projects/deassign/

    It performs the opposite of the notification; when a person “loses” a record because it is assigned to someone else, this workflow steps in and notifies that person that the record is no longer assigned to him/her.

    Very useful, and serves as a great (and simple) example.

    Andy

  3. 
    Matt Heitzenroder February 11, 2008 at 6:22 pm

    Thanks for the tip!

  4. 
    Matt Heitzenroder February 11, 2008 at 10:22 am

    Thanks for the tip!

Trackbacks and Pingbacks:

  1. Generar actividad recurrente basada en campo personalizado - SugarCRM Forums - October 2, 2011

    […] […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s