SugarCRM How To Add Custom Actions

Do you like this?

Summary:
Besides the default actions such as EDIT, DETAIL, LIST; we can add extra custom actions for any modules. This article shows you the steps to do that.


Content:

As an example, we are going to add a custom action for the Accounts module. Firstly, you have to create a file controller.php in the following directory:
SugarCRM How To Add Custom Actions 1

This is the content of the file controller.php

<?php
require_once('include/MVC/Controller/SugarController.php');

class AccountsController extends SugarController {
    
	function action_hello(){
		$this->view = 'helloActionView';
	}
}
?>


SugarCRM How To Add Custom Actions 2

A corresponding file has to be created for the view
SugarCRM How To Add Custom Actions 3

The content of the new view:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once('include/MVC/View/views/view.detail.php');

class ViewHelloActionView extends ViewDetail {


	function ViewHelloActionView(){
		parent::ViewDetail();
	}
	
	function display() {
		echo "hello";
	}

}

?>


SugarCRM How To Add Custom Actions 4

Now you have to create a mapping for the new action and the new view
SugarCRM How To Add Custom Actions 5

SugarCRM How To Add Custom Actions 6

To test the new action, open a browser and go to this page: /index.php?module=Accounts&action=hello SugarCRM How To Add Custom Actions 7

This is how the output looks like
SugarCRM How To Add Custom Actions 8

This is only a very simple example for adding custom actions. You can actually make queries to database and pull out more meaningful data to the output.
Another example about adding custom actions: SugarCRM Print Address Labels

 
comments powered by Disqus