Following Sugar Developper blog post:
http://developers.sugarcrm.com/wordp...-action-items/
Here is how I have added a Mass close opportunities on Listview.
(this is not upgrade safe until Sugar 620 which is what I used for my example. If you want to apply it to an older version, you will have to try to move the code to the non custom folder obviously..)
1. add a new controller file under custom/modules/opportunities/controller.php
PHP Code:
class CustomAccountsController extends SugarController
{
public function action_MassClose()
{
if ( !empty($_REQUEST['uid']) ) {
$recordIds = explode(',',$_REQUEST['uid']);
echo '<table border=1><TR BGCOLOR="#E8ADAA"><th> Opportunity </th><th> Update status </th></tr>';
foreach ( $recordIds as $recordId ) {
$bean = SugarModule::get($_REQUEST['module'])->loadBean();
$bean->retrieve($recordId);
if ($bean->sales_stage!='Closed Lost'){
global $db;
$result = $db->query("UPDATE opportunities SET sales_stage = 'Closed Lost' where id = '".$bean->id."'",true);
echo "<tr><td>".$bean->get_summary_text()."</td><td> Successfully changed to closed lost</td></tr>";
}
else{
echo "<tr><td>".$bean->get_summary_text()."</td><td> Warning, opportunity already closed lost</td></tr>";
}
}
echo "</table><br><a href=index.php?module=Opportunities&action=index>Go back to Opportunities List View</a>";
}
sugar_die('');
}
}
2. add button to listview actions
create a new view under custom/modules/opportunities/views/view.list.php
PHP Code:
require_once('include/MVC/View/views/view.list.php');
class CustomAccountsViewList extends ViewList
{
/**
* @see ViewList::preDisplay()
*/
public function preDisplay()
{
parent::preDisplay();
$this->lv->actionsMenuExtraItems[] = $this->buildMyMenuItem();
}
protected function buildMyMenuItem()
{
global $app_strings;
return <<<EOHTML
<a href='#' style='width: 150px' class='menuItem'
onmouseover='hiliteItem(this,"yes");' onmouseout='unhiliteItem(this);'
onclick="sugarListView.get_checks();
if(sugarListView.get_checks_count() < 1) {
alert('{$app_strings['LBL_LISTVIEW_NO_SELECTED']}');
return false;
}
document.MassUpdate.action.value='MassClose';
document.MassUpdate.submit();">
Mass close
</a>
EOHTML;
}
}
That's it!
Bookmarks