Custom Bulk menu item in custom module

I have got this working, so I thought I would share what worked for me.

The Class names seem to have a huge impact. The follow the format mentioned below.

custom/modules//controller.php



<?php
class <modulename>Controller extends SugarController
{
    public function action_displaypassedids() {
        if ( !empty($_REQUEST['uid']) ) {
            $recordIds = explode(',',$_REQUEST['uid']);
            foreach ( $recordIds as $recordId ) {
                $bean = SugarModule::get($_REQUEST['module'])->loadBean();
                $bean->retrieve($recordId);
                echo "Sent Record ID {$bean->id}, name ".$bean->get_summary_text()."";
            }
        }
        sugar_die('');
    } 
}



custom/modules//views/view.list.php


<?php

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

class Custom<modulename>ViewList extends ViewList
{
    /**
     * @see ViewList::preDisplay()
     */
    public function preDisplay()
    {
        parent::preDisplay();

        $this->lv->actionsMenuExtraItems[] = $this->buildMyMenuItem();
    }

    /**
     * @return string HTML
     */
    protected function buildMyMenuItem()
    {
        global $app_strings;
    
        return <<<EOHTML
<a class="menuItem" style="width: 150px;" href="#" onmouseover='hiliteItem(this,"yes");' 
        onmouseout='unhiliteItem(this);' 
        onclick="sugarListView.get_checks();
        if(sugarListView.get_checks_count() &lt; 1) {
            alert('{$app_strings['LBL_LISTVIEW_NO_SELECTED']}');
            return false;
        }
        document.MassUpdate.action.value='displaypassedids';
        document.MassUpdate.submit();">Send records to a new view!</a>
EOHTML;
    }
}
1 Like