Results 1 to 3 of 3

Thread: firing before_save hook when User saves, but not through code save

  1. #1
    nlaan Guest

    Default firing before_save hook when User saves, but not through code save

    Hi everyone,

    I have a before_save hook in the Opportunities module.
    I also have an after_save hook in the Accounts module that saves all related Opportunities.

    Now I want to fire the Opportunities' before_save hook when a User saves an Opportunity, but not when the Opportunity is saved through code from the Accounts' after_save hook.

    Any help appreciated,
    nlaan

  2. #2
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Germany
    Posts
    1,539

    Default Re: firing before_save hook when User saves, but not through code save

    You could set a special flag when saving the Opportunity in your Accounts' after_save hook and check this flag when the Opportunities' before_save hook is called (and do nothing in that case but resetting the flag).
    Stefan Ulrich Sauer
    System Analyst

    Devoteam GmbH
    Gutenbergstraße 10
    D-64331 Weiterstadt
    Germany
    email: Stefan-Ulrich.Sauer@devoteam.com
    http://www.devoteam.com
    http://www.devoteam.de

  3. #3
    nlaan Guest

    Default Re: firing before_save hook when User saves, but not through code save

    Thanks for the answer, it works perfectly.


    Accounts after_save hook

    $opp = new Opportunity();
    $opp->retrieve($_REQUEST['return_id']);
    $opp->save_opp_from_code=1;
    $opp->save();



    Opportunities before_save hook

    if($bean->save_opp_from_code==1 || $_REQUEST['module'] != 'Opportunities'){
    unset($bean->save_opp_from_code);
    }
    else{
    //here goes the hook logic

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Firing before_save logic hook from QuickCreate
    By jm_phila in forum Developer Help
    Replies: 11
    Last Post: 2014-01-24, 01:55 PM
  2. Calling Save() in before_save logic hook
    By tobydz in forum Developer Help
    Replies: 5
    Last Post: 2013-08-01, 05:42 PM
  3. before_save logic hook (SugarCRM CE 6.5.7) not firing
    By SpockPT in forum Developer Help
    Replies: 2
    Last Post: 2012-10-31, 06:04 PM
  4. Logic Hook not Firing after Log Call save?
    By bstonehill in forum Developer Help
    Replies: 1
    Last Post: 2010-11-10, 04:15 PM
  5. Please check my logic hook code - Not Firing
    By bstonehill in forum Help
    Replies: 12
    Last Post: 2010-01-22, 04:26 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
  •