How to Create Custom Actions, Add Them in List View, and Include Them in the Module Menu

I recently worked on a task to create custom actions in the Accounts module of SuiteCRM. The goal was to display accounts based on their type and integrate these actions into the module menu for easy access. Here’s a step-by-step breakdown of how I achieved it:

  • Create custom actions (CustomerPartnersAccounts & OtherThanCustomerPartnersAccounts).
  • Call a custom list view that filters accounts based on the account_type field.
  • Add these actions to the module menu for easy navigation.

1. Define Custom Actions in Controller:

  • I started by defining two custom actions inside the Controller:

File Path: custom/modules/Accounts/Controller.php

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

class AccountsController extends SugarController
{
    public function action_CustomerPartnersAccounts()
    {
        $this->view = 'customerpartnersaccounts';
    }

    public function action_OtherThanCustomerPartnersAccounts()
    {
        $this->view = 'otherthancustomerpartnersaccounts';
    }
}

2. Create Custom List Views:

  • View for Customer & Partner Accounts

File Path: custom/modules/Accounts/views/view.customerpartnersaccounts.php

<?php
require_once 'include/MVC/View/views/view.list.php';

class AccountsViewCustomerPartnersAccounts extends ViewList
{
    public function listViewProcess()
    {
        $this->params['custom_where'] = " AND accounts.account_type IN ('Customer', 'Partner')";
        parent::listViewProcess();
    }

    public function display()
    {
        echo "<h2 style='padding: 10px; color: #d66c60;'>Customer and Partner Accounts</h2>";
        parent::display();
    }
}
  • View for Other Than Customer & Partner Accounts

File Path: custom/modules/Accounts/views/view.otherthancustomerpartnersaccounts.php

<?php
require_once 'include/MVC/View/views/view.list.php';

class AccountsViewOtherThanCustomerPartnersAccounts extends ViewList
{
    public function listViewProcess()
    {
        $this->params['custom_where'] = " AND accounts.account_type NOT IN ('Customer', 'Partner')";
        parent::listViewProcess();
    }

    public function display()
    {
        echo "<h2 style='padding: 10px; color: #d66c60;'>Other Than Customer and Partner Accounts</h2>";
        parent::display();
    }
}

3. Add Actions to the Module Menu

  • To make these actions easily accessible, I added them to the Accounts module menu:

File Path: custom/Extension/modules/Accounts/Ext/Menus/customerpartnermenu.php

<?php
if (ACLController::checkAccess('Accounts', 'list', true)) {
    $module_menu[] = array(
        "index.php?module=Accounts&action=CustomerPartnersAccounts",
        "Customer & Partner Accounts",
        "Accounts"
    );
    $module_menu[] = array(
        "index.php?module=Accounts&action=OtherThanCustomerPartnersAccounts",
        "Other than Customer & Partner Accounts",
        "Accounts"
    );
}
2 Likes