Results 1 to 2 of 2

Thread: How to: mass close opportunities on listview

  1. #1
    guigui is offline Sugar Community Member
    Join Date
    Jun 2010
    Posts
    54

    Default How to: mass close opportunities on listview

    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!
    Last edited by guigui; 2011-06-06 at 05:09 PM.

  2. #2
    ashdwi1's Avatar
    ashdwi1 is offline Sugar Community Member
    Join Date
    May 2008
    Location
    Noida
    Posts
    198

    Default Re: How to: mass close opportunities on listview

    that was nice
    Almost available at skype or gtalk at ashdwi1.

    SugarForge Project:
    http://www.sugarforge.org/projects/gmapdirection
    Email: ashdwi1@gmail.com
    Mob: +919005468298

    Hire us at Odesk at
    https://www.odesk.com/users/~~b9eff8ff219fd705

    Hire Us at Elance at:
    http://ashdwi1.elance.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 2011-05-10, 05:33 PM
  2. Mass create opportunities
    By xadora in forum Developer Help
    Replies: 0
    Last Post: 2009-12-29, 08:17 PM
  3. Replies: 2
    Last Post: 2008-07-24, 08:07 PM
  4. Reports: listview and mass update
    By dcurrie in forum General Discussion
    Replies: 0
    Last Post: 2007-09-17, 07:27 PM
  5. Opportunities - ListView
    By kbrill in forum Developer Help
    Replies: 1
    Last Post: 2004-07-28, 02:58 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •