Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: logic hooks create new record

  1. #1
    blitz2190 is offline Senior Member
    Join Date
    Jul 2009
    Posts
    105

    Default logic hooks create new record

    ok so i am new to sugarcrm but i have a fair background in php. My problem is that i cannot seem to get the hook to fire when i am creating a new record in a custom module. i have successfully done this when editing a current record using after_retrieve but i cannot seen to get before_save which i think is the right one to work

    by the way this is on sugar 5.2f ce

    for the hook it is

    PHP Code:
    <?php
    $hook_array
    ['before_save'] = Array();
    $hook_array['before_save'][] = Array(1'custom2''custom/include/Products/productsdrop.php','Before''Before');
    ?>
    this is to populate a dropdown for selecting which product to associate the info with

    any help will be greatly appreciated

  2. #2
    josh.sweeney is offline Sugar Community Member
    Join Date
    Apr 2008
    Location
    Ga
    Posts
    339

    Default Re: logic hooks create new record

    Have you tried putting a breakpoint in the hook to see if it is getting triggered?

  3. #3
    dekleinemedia is offline A Prolific Poster
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    241

    Default Re: logic hooks create new record

    Quote Originally Posted by blitz2190 View Post
    ok so i am new to sugarcrm but i have a fair background in php. My problem is that i cannot seem to get the hook to fire when i am creating a new record in a custom module. i have successfully done this when editing a current record using after_retrieve but i cannot seen to get before_save which i think is the right one to work

    by the way this is on sugar 5.2f ce

    for the hook it is

    PHP Code:
    <?php
    $hook_array
    ['before_save'] = Array();
    $hook_array['before_save'][] = Array(1'custom2''custom/include/Products/productsdrop.php','Before''Before');
    ?>
    this is to populate a dropdown for selecting which product to associate the info with

    any help will be greatly appreciated

    Hi,

    Add the below code in the top of your script

    For Example: logic_hooks.php

    Code:
    echo "Test";
    exit;

    Repair and Rebuild and run the logic hook
    Kind regards,

    De Kleine Media


    SugarCRM CE v.5.2.0h
    Windows platform
    MySQL v.5.1
    phpMyAdmin - 2.11.2.2
    Apache Server v.2.0

  4. #4
    gsrikanth's Avatar
    gsrikanth is offline Sugar Community Member
    Join Date
    Dec 2008
    Location
    Hyderabad
    Posts
    49

    Default Re: logic hooks create new record

    Hi,

    put a die/exit statement in your productsdrop.php file,and confirm the trigger.

  5. #5
    blitz2190 is offline Senior Member
    Join Date
    Jul 2009
    Posts
    105

    Default Re: logic hooks create new record

    sorry i forgot to mention that the hooks fires when i click save or when in edit view if i use after_retrieve. but what i need it to do is populate a dropdown box when the user clicks "create new case" in this case and the dropdown should be populated.

    so what im trying to say is i know the hook works but not at the time i need it to, when the create new case page loads.

    also on a side note i was researching and i found something on global logic_hooks and was wondering if that could be applied here
    Last edited by blitz2190; 2009-07-10 at 02:23 PM. Reason: info

  6. #6
    edg
    edg is offline Sugar Community Member
    Join Date
    Feb 2007
    Location
    Atlanta, GA
    Posts
    46

    Default Re: logic hooks create new record

    'after_retrieve' is not called on a new record because no record is being retrieved.

    try using 'process_record'

  7. #7
    blitz2190 is offline Senior Member
    Join Date
    Jul 2009
    Posts
    105

    Default Re: logic hooks create new record

    ok tried

    PHP Code:
    <?php
    $hook_array
    ['after_retrieve'] = Array();
    $hook_array['after_retrieve'][] = Array(1'custom2''custom/include/Cases/productsdrop.php','Before''Before');
    $hook_array['process_record'] = Array();
    $hook_array['process_record'][] = Array(2'custom3''custom/include/Cases/productsdrop.php','Before''Before');
    echo 
    "hello";
    ?>
    and still no go but i did relise that it only echos hello when going to edit and not to create so i am thinking the hook is not being called at all

  8. #8
    blitz2190 is offline Senior Member
    Join Date
    Jul 2009
    Posts
    105

    Default Re: logic hooks create new record

    i solved it by adding the code to populate my dropdown to

    custom/include/language/en_us.lang.php

    but my question is now will this be upgrade safe

  9. #9
    edg
    edg is offline Sugar Community Member
    Join Date
    Feb 2007
    Location
    Atlanta, GA
    Posts
    46

    Default Re: logic hooks create new record

    Sorry - I forgot how I did this.

    Create a custom view.edit.php and overload the predisplay() function. Add in the logic_hook you want to call.

    Code:
      function predisplay(){
              global $mod_strings;
              parent::predisplay();
              if (!$this->bean->id) $this->bean->call_custom_logic('process_record');
      }
    I just happen to use process_record so it was different than after_retrieve when the object existed. You can then test for that event and handle things differently if necessary. Another option is to simply check if $bean->id is set instead of issuing a different event type in the logic hook.

  10. #10
    blitz2190 is offline Senior Member
    Join Date
    Jul 2009
    Posts
    105

    Default Re: logic hooks create new record

    that sounds much more elegant than editing the language file ill give that a try thank you for the help

Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Create/Edit logic hooks from Admin
    By mvngti in forum Downloads
    Replies: 20
    Last Post: 2011-07-01, 09:12 AM
  2. What logic hook should I use before create new record
    By AlexCh in forum Developer Help
    Replies: 4
    Last Post: 2010-08-10, 09:12 PM
  3. How make logic hook for create new record
    By meeric in forum Developer Help
    Replies: 6
    Last Post: 2009-01-02, 07:49 AM
  4. Logic Hooks
    By Delos in forum Developer Help
    Replies: 0
    Last Post: 2008-10-17, 01:01 AM
  5. logic hooks
    By user1000 in forum Developer Help
    Replies: 3
    Last Post: 2008-05-06, 07:51 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
  •