HOWTO: Adding your own ListView action items

Matthew Marum —  November 22, 2010 — 35 Comments

We are always on the outlook to help provide our developers easier and more upgrade-safe methods to make customizations to SugarCRM. Today I’m going to show you how to do one customization we added in Sugar 6, as a response from a suggestion we had brought up by a partner of ours back at SugarCon this past spring. It also came up in the forums recently, so I felt it was appropriate to bring it up on the developer blog today

This customization involves the action items that are at the top of the ListView records and how to add your own items to the list. Prior to Sugar 6 were a series of buttons along right above the header, but we changed in Sugar 6 to be a dropdown menu as shown below.

So to enable this, we added a new property to the ListViewDisplay class named $actionsMenuExtraItems, which is an array of HTML elements to add to this menu list. The elements are pure HTML, so you can easily build the item and the action to take when the item is clicked. The best way to define these items is by overriding the default list view and defining it yourself in the custom directory. So if we wanted to add a new action menu item “Send records to a new view!” item to the Accounts module menu, we could do it as follows below.

The first part of this customization is to create the action menu item, which we build in the buildMyMenuItem() method. The menu item is a simple anchor element, where we set the onclick property of it populate the uid form value ( using the sugarListView.get_checks() call ), then check to make sure at least one record is checked ( by making sure the sugarListView.get_checks_count() is greater than zero ) and then finally by setting the action we will redirect to and submitting the form to it.

The next half is to create an action to receive the form post from the above menu item. We can do this easily with a custom Accounts controller, as shown below.

The list of records that were checked in the listview is provided by a comma delimited list in the uid request variable. We can use explode() to make this into an array, and then iterate over it to display the records sent to it.

You can use this example as the basis for adding all sorts of action menu items to listviews.

Matthew Marum


Matt is the Director of Developer Advocacy for SugarCRM. Previously he was an Engineer on Sugar 7 and a Solutions Architect for the OEM program. He is also an avid trail runner, Boston Marathon qualifier and a karaoke aficionado.

35 responses to HOWTO: Adding your own ListView action items


    Where is the code above placed [what file] if you want to modify the listview action items for a single custom module?


    modules//views/view.list.php and modules//controller.php


    Following line is wrong

    if ( !emptyempty($_REQUEST[‘uid’]) ) {

    It must be

    if ( !empty($_REQUEST[‘uid’]) ) {


    If anyone has trouble with this code, I had to do this:

    return “<a href='#' style='width: 150px' class='menuItem' onmouseover='hiliteItem(this,"yes");' onmouseout='unhiliteItem(this);' onclick="sugarListView.get_checks();if(sugarListView.get_checks_count() New Menu Item“;

    Also, I think John mean to do this for the file locations:

    Good article John!


    Whoops. The comments won’t let me put in the full html. On lines 27 to 33 above, take out the whitespaces and returns in the javascript onclick event or the menu won’t show up correctly.


    Thanks for catching the typo above; it’s more of a problem with the code formatting plugin we were using.

    As for Swhitlow’s comment, this problem will be fixed in 6.2


    where i can write the new action item name .. in which file and at what path.?


    For the above example, this would be in the custom/modules/Accounts/views/view.list.php file.


    Implemented a custom action awhile ago, and I’m just now coming across an issue when specifying “Select All”. The uid array only contains the first page of records, whereas I would need all ids from the search results. Currently just grabbing the searches where clause from $_SESSION, but was curious if there’s a better way?


      I ran into the same problem and spent hours on that. Grabbing the query field in $_SESSION seems to be the only solution.


        Could you kindly give more details what it means “to grab the query field in the $_SESSION” or “grabbing the searches WHERE clause from $_SESSION”?

        We would like to understand how to do this, because we’ve run into the same issue of receiving only the first pages instead of all the selected IDs.


      How did you fixed the issue when using “Select All”?


    Hello? Hi I tried your code on 6.5 community Edition and it did not work. the “<<<eohtml" part is the one that is the error. It says a syntax error. What is this? and by the way, as what I have seen in the code the "{" and "}", is that correct? and also line 31, what is that suppose to be? Please Help. Hope this is still alive.


    Let me do that again… I tried your code on 6.5 Community Edition and it did not work. the ” < < < e o html" has been the problem showing in my logs. It says a syntax error occured. Is there something to be done first before inserting this code? and line 31 – 33, is that right? Please help.


    Por favor, alguien me puede ayudar a implementar este ejemplo. He tratado utilizando el código pero no funciona. Gracas.


    Thanks a lot for this article! I would like to add a button to the listview of several modules not only to a specific module. How can I do this? I am thinking about using javascript to add the button after the page has loaded.. but maybe there as a simpler solution out there?!


    I realize this is a few years old now. I was able to add the Button in my custom view list and can verify that it is adding a hidden form field for action.value=’displaypassedids’ and I have in my Controller an Action method for that however when the Button is clicked instead of POSTing to this Controller Action it goes to the root of my Sugar install URL. Any ideas why it would now post to the correct module and url?


    Any idea how to do this to add a duplicate button just like in the record view?


    I have created a manifest file to install my custom action items so that I can install them and remove them with module loader.
    My problem is that the files custom/modules/Accounts/views/view.list.php and custom/modules/Accounts/controller.php alreay exist.
    Is it possible to create them with a different name? Or how would I tell the manifest file to add/remove my code in the existing files?

Trackbacks and Pingbacks:

  1. Adding a Custom Action item in the List View - SugarCRM Forums - December 29, 2011

    […] Action menu on the List View of one of our custom modules. I followed this developer blog article: Adding your own ListView action items, but I can't get the item that I add in the code to show up in the LIstView's Action menu. Here is […]

  2. Popup Data Picker - Page 2 - SugarCRM Forums - January 1, 2012

    […] […]

  3. Custom action buttons in listview - April 26, 2012

    […] […]

  4. Adding Email as ListView action item for Custom Module - July 5, 2012

    […] […]

  5. Listview Action Button Role Restriction - July 11, 2012

    […] of the Contacts Module i achieved this by following john Mertic's post in the developer zone HOWTO: Adding your own ListView action items now that i have created my new action i am noticed that it is available to all users and in […]

  6. Button - July 11, 2012

    […] […]

  7. SugarCRM Developer Blog » Blog Archive » Removing the stock ListView actions items for a module - August 28, 2012

    […] you remember way back when, we had a good blog post here talking about how to extend the ListView actions menu to put in new action items. But what if there […]

  8. Adding new button on subpanel in Accounts module - October 9, 2012

    […] […]

  9. how create list view buttions mass update,emil ,import here i want add one buttion th - November 12, 2012

    […] […]

  10. Mass Update Customisation - December 2, 2012

    […] […]

  11. add custom action in menu of listview and add it in acl. - April 24, 2013

    […] […]

  12. Adding your own ListView action items | Educational Info - November 11, 2013

    […] […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s