Results 1 to 5 of 5

Thread: HELP! How to customize save function

  1. #1
    fedepia is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Rosario, Argentina
    Posts
    104

    Exclamation HELP! How to customize save function

    Hello people, how are you? I'm using SugarCRM 4.5 (OS), and that i'm trying to do is customize a save account function, i.e.:

    first at all, when a user goes to the Accounts module if he wants to create one, he has to put a name for it and then he could create the account, but, with a logic hooks (using a before_save event) i have to insert a Lead (or whatever) before the insert of the account.

    so, i have my logic hook and my class with its method that handles the event, if all went ok, there are two inserts (first a Lead then an account).

    but, i have to check if sugar really could insert the account, because if it couldn't then i have to delete the lead, i.e.:
    1) Insert a lead before save an account -----> OK
    2) Sugar's account insert -----> FAIL
    3) Must delete lead in '1'

    however, sugar doesn't provide a after_save hook where i can delete the lead, so i looked at one link where someone said that it had to customize the Save.php file, but, it doesn't work

    in my before_save method, i put the id lead on $_SESSION and at the last in Save.php i retrieve that id but didn't work.

    Any sugerence?

    Thank you people

  2. #2
    sacramentojoe is offline Sugar Community Member
    Join Date
    Nov 2005
    Posts
    447

    Default Re: HELP! How to customize save function

    Well, I would use the existing code and create a Lead Object.
    Calling Save on the Lead Object will return the ID of the lead that was just inserted if you left the id blank.
    $focus = new Lead();
    $focus->first_name = 'blah';
    $focus->save();


    If you want to delete it, just call
    $focus = new Lead();
    $focus->retrieve($lead_id);
    $focus->deleted = 1;
    $focus->save();

    When a file is saved, the next page automatically loads, so you should be able to use the after_retrieve.

    You can always just throw ALL of your code at the end of the save.php file too.

    Sorry I don't have a DIRECT answer, but I hope this helps some.

  3. #3
    fedepia is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Rosario, Argentina
    Posts
    104

    Default Re: HELP! How to customize save function

    hi sacrajoe, thank you for reply.
    I inserted a lead but that i have to resolve is to call a web service on a before_save event, then if sugar fail on save, i have to cancel the lead created.
    so, for other reason i have to use the set_entry web service for insert before save and for mark as deleted the lead.

    the question is not to insert a lead but to do a web service call on other system (and this ws call is like the set_entry)

    cheers!

  4. #4
    youssefaoun is offline Sugar Community Member
    Join Date
    Apr 2007
    Posts
    55

    Default Re: HELP! How to customize save function

    You may alter the save function and make it call an event: after_save and in the event you create a TESTING algorithm in which you test the results of the SAVE and you decide whether or not to keep the LEAD

    PHP Code:
    function save($check_notify FALSE){
        
    $ret parent::save($check_notify);
        
    parent::call_custom_logic("after_save"'');
        return 
    $ret;

    Of course you should create your logic:
    PHP Code:
    require_once('include/utils.php');
    echo 
    "Subscribing to Cases<br>";
    check_logic_hook_file(    "Cases"
                            
    "before_save"
                            array(    
    1
                                    
    "insert1",
                                    
    "modules/mymod/Cases_events.php"
                                    
    "casesEvt"
                                    
    "before_save"));

    echo 
    "            Subscribing to before_save<br>";
    check_logic_hook_file(    "Cases"
                            
    "after_save"
                            array(    
    2
                                    
    "insert2",
                                    
    "modules/mymod/Cases_events.php"
                                    
    "casesEvt"
                                    
    "after_save"));

    echo 
    "            Subscribing to after_save<br>"
    and

    PHP Code:
    class casesEvt{
        
        function 
    before_save(&$bean$event$arguments) {
        }
        
        function 
    after_save(&$bean$event$arguments) {
            }

    Youssef AOUN
    Software Eng.

  5. #5
    fedepia is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Rosario, Argentina
    Posts
    104

    Default Re: HELP! How to customize save function

    hello youssefaoun, thanks your reply. I'd use the after_save event, but im using sugar4.5 a it doesn't exist in this version, only for version 5.0

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Cancel save in logic hook
    By eggsurplus in forum Developer Help
    Replies: 4
    Last Post: 2012-02-08, 09:37 AM
  2. Replies: 1
    Last Post: 2007-09-15, 02:59 PM
  3. Replies: 0
    Last Post: 2007-08-08, 02:47 PM
  4. Row_number is not a recognized function
    By theoracleprodigy in forum Help
    Replies: 4
    Last Post: 2007-04-10, 04:58 PM
  5. export function in Accounts save button
    By daska in forum Developer Help
    Replies: 2
    Last Post: 2006-07-14, 07:47 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
  •