Results 1 to 4 of 4

Thread: Validations on Delete from ListView (Massupdate)

  1. #1
    jasv is offline Sugar Community Member
    Join Date
    Sep 2008
    Posts
    98

    Default Validations on Delete from ListView (Massupdate)

    Hi Everyone,

    I'd like make some validations on the ListView when i click on Delete Button. i.e. To validate that an Account cannot be delete if it has Opportunities associated.

    My question is, Where this validations must be done???

    Thanks in advance. Cheers.

  2. #2
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: Validations on Delete from ListView (Massupdate)

    I'm sure Andopes has an upgrade-safe way of doing this ( ) but here's a not-upgrade-safe way. Open include/MassUpdate.php and look for this section of code:
    PHP Code:
                    if(isset($_POST['Delete'])){
                        
    $this->sugarbean->retrieve($id);
                        if(
    $this->sugarbean->ACLAccess('Delete')){
                            
    $this->sugarbean->mark_deleted($id);
                        }
                    } 
    And add a check to see if it is an Account bean and if there is an opportunity associated with it:

    PHP Code:
                    if(isset($_POST['Delete'])){
                        
    $this->sugarbean->retrieve($id);
                        if(
    $this->sugarbean->ACLAccess('Delete')){
                                                if(
    $this->sugarbean->object_name == 'Account') {
                                                          
    //check to see if an opp is associated to this account...if so do NOT delete
                                                          
    $this->sugarbean->get_linked_beans('opportunities','Opportunity');
                                                          if(empty(
    $this->sugarbean->opportunities)) {
                                       
    $this->sugarbean->mark_deleted($id);
                                                          }
                                                } else {
                            
    $this->sugarbean->mark_deleted($id);
                                                }
                        }
                    } 
    This has not been verified to work so please test first.

    Good luck!

  3. #3
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Validations on Delete from ListView (Massupdate)

    Hi eggsurplus

    I believe you had got the best non-upgrade safe way to do this.
    I browsed a bit into code and it seems there is no upgrade way to perform this action.
    Congratulations.

    Best regards
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  4. #4
    jasv is offline Sugar Community Member
    Join Date
    Sep 2008
    Posts
    98

    Default Re: Validations on Delete from ListView (Massupdate)

    Hi, thanks for the answer...

    I had to do a change to make it work. I do not know if it is optimum, but it works for me.

    PHP Code:
         if($this->sugarbean->object_name == 'Account') {
                  
    //check to see if an opp is associated to this account...if so do NOT delete
                  
    $opp $this->sugarbean->get_linked_beans('opportunities','Opportunity');
                  if(
    count($opp)==0) {
                        
    $this->sugarbean->mark_deleted($id);
                  }
         }else{
                  
    $this->sugarbean->mark_deleted($id);
         } 
    If you have another advice please tell me... anyway thanks a lot... right now the issue is solved....

    Cheers.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Same record multible times in Listview
    By jones70 in forum Help
    Replies: 5
    Last Post: 2011-01-28, 04:47 AM
  2. remove delete button from listview
    By mikesolomon in forum Developer Help
    Replies: 13
    Last Post: 2008-10-02, 10:14 AM
  3. Delete via massupdate vs Delete from DetailView
    By tj@estreet.com in forum Help
    Replies: 2
    Last Post: 2007-05-25, 04:10 PM
  4. You CAN massupdate non-dropdown fields
    By tj@estreet.com in forum Help
    Replies: 0
    Last Post: 2006-10-03, 05:01 PM

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
  •