One of the coolest features of SuiteCRM is Advanced Open Workflow(AOW) and the best thing about a Workflow is its Action(s). In this blog, we will go through the basic process of building a Custom Action for SuiteCRM Workflows and extending its ability.
To learn more about Workflows, you can visit SuiteCRM Wiki for AOW here.
What is an Action in Workflow?
Actions are those events, which are triggerred when some specific conditions have been met.
For Example: Sending Emails when a field value changes from Yes to No in CRM, Modifying Records when there is any change in a field value.
What is a Custom Action?
As the title says, a Custom Actions allows you to perform custom things when an action is triggerred.
For Example: Calling external API when a record is Updated.
Creating Custom Actions
At last, when you are introduced enough, let us move forward in creating a Custom Action.
Before proceeding, we assume that you have novice knowledge of PHP, JavaScript and HTML.
Setup
First of all, you need to setup some things before you proceed with Coding your action. This is because SuiteCRM maintains a proper directory structure for managing its modules and we have to follow the same conventions.
Directory Structure
The Default actions which are delivered inside SuiteCRM package, can be found in the directory /modules/AOW_Actions/actions/.
The Custom actions are placed inside the directory /custom/modules/AOW_Actions/actions/.
» Note: If the directories for Custom Actions doesn’t already exist, create them.
Adding Custom Action
Step 1:
The first thing is to tell SuiteCRM about our new custom action. Edit the file located at /modules/AOW_Actions/actions.php and add your Action in the $aow_actions_list array as:
$aow_actions_list[] = 'MyAction';
Now, to give your Action a Label which is shown in Add Action in Workflows, edit the file /modules/AOW_Actions/language/en_us.lang.php and Add your label to $mod_strings array as:
'LBL_MYACTION' => 'My Custom Action'
Step 2:
Now, SuiteCRM will automatically Search for a file located at /custom/modules/AOW_Actions/actions/actionMyAction.php. So, the 2nd step is to create this PHP file.
Create the PHP file with the following Code in it:
<?php require_once('modules/AOW_Actions/actions/actionBase.php'); class actionMyAction extends actionBase { function actionMyAction($id = '') { parent::actionBase($id); } function loadJS() { parent::loadJS(); return array(); } function run_action(SugarBean $bean,$params = array()) { // This is called when the Action is triggerred. It should return Boolean. return true; } function edit_display($line, SugarBean $bean = null, $params = array()) { $html = "<h1>Your HTML Code for View of your Action</h1>"; return $html; } } ?>
After all these steps are done, perform a Quick Repair of CRM by going to Admin → Repair → Quick Repair and Rebuild.
Now you will be able to see your Basic Action interface in Workflow module just like shown below:
What Next?
Now, you have successfully created a basic Action for the Workflow module. We will learn more about Retrieving Modules Data and performing some more actions in the next part of this Tutorial.
Tags: crm, sugarcrm, suitecrm, Tech, workflow
4 Comments