Call Action custom controller

Hello everyone, my name is Massimo,

I created a custom controller that makes a call to an external web server and returns information that will update sugar crm,

in this controller, I created an action like below:

class prv_GestionePreventiviController extends SugarController{

public function action_generaPreventivo(){


how can I recall this action from the button created in the detail of the view ??

thanks everyone in advance

Hi Massimo,

Firstly, there is no need to extend the controller class. Assuming your class is named “prv_Gestione” A little cleaner would be to create the file:


with the contents


$action_file_map['generaPreventivo'] = 'custom/modules/prv_Gestione/generaPreventivo.php';

Then add your code in the file:


You can access the respective bean in this file by


if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

$myGestione = new prv_Gestione;

To trigger the action, edit the following file (if it doesn’t exist, then create a copy from modules/prv_Gestione/metadata/detailviewdefs.php)


Add the following code to the bottom of this file, or integrate it in the $viewdefs array:

$viewdefs['prv_Gestione']['DetailView']['templateMeta']['form']['buttons']['GENERA_PREVENTIVO'] = array (
	'customCode' => '<input />',
	'sugar_html' => array (
		'type' => 'submit',
		'value' => '{$MOD.LBL_GENERA_PREVENTIVO}',
		'htmlOptions' => array (
		'class' => 'button',
		'id' => 'genera_preventivo_button',
		'title' => '{$MOD.LBL_GENERA_PREVENTIVO}',
		'onclick' => "window.location='index.php?module=prv_Gestione&action=generaPreventivo&record={$bean->id}'",
		'name' => 'genera_preventivo_button'

Finally, to define the text for the button, create the following file:


with the contents

$mod_strings['LBL_GENERA_PREVENTIVO'] = 'Genera preventivo';

Afterwards, do a Admin -> Repair -> “Quick Repair and Rebuild”


Hello, thanks for your help, I implemented the code as you suggested, but it goes wrong saying that there is no defined action, you have some ideas I thank you in advance

Thu Jan  3 09:46:25 2019 [8598][1][FATAL] Exception handling in /var/www/html/Kredias/include/MVC/Controller/SugarController.php:400
Thu Jan  3 09:46:25 2019 [8598][1][FATAL] Exception in Controller: Non c'è nessuna azione con il nome: generaPreventivo
Thu Jan  3 09:46:25 2019 [8598][1][FATAL] backtrace:
#0 /var/www/html/Kredias/include/MVC/Controller/SugarController.php(555): sugar_die('Non c'\xC3\xA8 nessun...')
#1 /var/www/html/Kredias/include/MVC/Controller/SugarController.php(1094): SugarController->no_action()
#2 /var/www/html/Kredias/include/MVC/Controller/SugarController.php(468): SugarController->handleActionMaps()
#3 /var/www/html/Kredias/include/MVC/Controller/SugarController.php(373): SugarController->process()
#4 /var/www/html/Kredias/include/MVC/SugarApplication.php(113): SugarController->execute()
#5 /var/www/html/Kredias/index.php(52): SugarApplication->execute()
#6 {main}

if matter is just calling this new action , just put in this way


1 Like

Thanks work…

Hi, how can I retrive the bean id ?? it turns out to be empty in modules/prv_Gestione/metadata/detailviewdefs.php)

‘onclick’ => “window.location=‘index.php?module=prv_Gestione&action=generaPreventivo&record={$bean->id}’”,


In case if anyone looking for this answer

replace $bean->id with $ or $this>bean->id