–– Support ––

News and Blogs

This is some blog description about this site

Workflow - Adding a Custom Action

One of the great things about workflow is the ability to add you own custom actions that are completely upgrade safe and blend in just as if they where there all along.  In this example we are going to add a custom action that simply logs to the sugarcrm.log, not very useful but it will make a nice example!

To start we will create a new file 'actionNewAction.php' in 'custom/modules/AOW_Actions/actions' that extends the base action. You can extent any of the current action if your action is similar or you can make use of the current functionality, but for this example we will just use the base:-

php

require_once('modules/AOW_Actions/actions/actionBase.php');

class actionNewAction extends actionBase {

    function actionNewAction($id = ''){

        parent::actionBase($id);

    }

?>

Now we have our class file, we can add a new method 'run_action' to do the new action, which is passed two parameters $bean the workflow bean this is running for and $params which we will cover in part 2:-

    function run_action(SugarBean $bean, $params = array()){

       $GLOBALS['log']->fatal($bean->name' ran in Wokflow!!!');

        return true;

    }

Now we have created our class file and set its run action, we need to add it to the workflow actions dropdown and to do that we need to create a file called anything relevant like 'myNewAction.php' in 'custom/Extension/modules/AOW_Actions/Ext/Actions'  and add it to the array using the same name as out new action:-

?php

$aow_actions_list[]='NewAction';

And finally for out action to display nicely in the dropdown we add a language entry for all languages you want it to display in, English in my case, so create a new file 'en_us.myNewAction' in 'custom/Extension/modules/AOW_Actions/Ext/language' and the appropriate language string for you action:-

?php

$mod_strings['LBL_NEWACTION']='My New Action';

Quick repair and Rebuild and your new action is ready to go!

In Part2 we will look adding options to display when creating and editing the action, to make our action more flexible.

Workflow – What's it all about!
Open Source at it's best
 

Comments 1

Guest - mehrshid on Friday, 16 August 2013 01:50

Great Article!

0
Great Article!