Results 1 to 3 of 3

Thread: Logic Hooks to add fields

  1. #1
    joeya is offline Senior Member
    Join Date
    Jan 2010
    Location
    Chile
    Posts
    37

    Unhappy Logic Hooks to add fields

    (Sorry for my English, but my native language is Spanish)

    Hello!
    I'm a beginner in SugarCRM, and that maybe I have a question for many people seem simple.
    I need to add two fields and display the result in a third field, I found the forum that this is done with logic hook, but I have a lot of confusion in my head, because apparently native modules for SugarCRM is a way for modules and Custom otherwise. I'm confused.
    What I have done so far is as follows:

    The module is b1c2d_Probabilidades, and its path is C: \ Program Files \ sugarcrm-5.5.1RC \ htdocs \ sugarcrm \ custom \ ModuleBuilder \ builds \ Prob \ SugarModules \ modules \ b1c2d_Probabilidades

    Fields are I think add LBL_PLAZO and LBL_ANTECEDENTE, I say "think" because SugarCRM and named them automatically when you create them with the module builder (System Label:LBL_PLAZO) .

    So what we've done is:
    Create suma.php file in C: \ Program Files \ sugarcrm-5.5.1RC \ htdocs \ sugarcrm \ custom \ ModuleBuilder \ builds \ Prob \ SugarModules \ modules \ b1c2d_Probabilidades \ suma.php
    which contains the following code:

    if (defined ( 'sugarEntry') | |! sugarEntry) die ( 'Not A Valid Entry Point');

    class sum (
    calculateField function (& $ focus, $ event, $ arguments) (
    $ focus-> amount = $ focus-> LBL_PLAZO + $ focus-> LBL_ANTECEDENTE;
    )
    )

    Then, I modified the file b1c2d_Probabilidades.php, located in
    C: \ Program Files \ sugarcrm-5.5.1RC \ htdocs \ sugarcrm \ custom \ ModuleBuilder \ builds \ Prob \ SugarModules \ modules \ b1c2d_Probabilidades \ b1c2d_Probabilidades.php

    I modify it as follows:

    <?php require_once('modules/b1c2d_Probabilidades/b1c2d_Probabilidades_sugar.php');
    class b1c2d_Probabilidades extends b1c2d_Probabilidades_sugar {

    function b1c2d_Probabilidades(){
    parent::b1c2d_Probabilidades_sugar();
    }

    //I did from this

    function retrieve($id) {
    parent::retrieve($id);

    $hook_version = 1;
    $hook_array = Array();

    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1, 'suma', 'custom\modulebuilder\builds\Prob\SugarModules\mod ules\b1c2d_Probabilidades\suma.php', 'suma', 'suma');

    return $this;
    }

    function save($check_notify = false) {
    $hook_version = 1;
    $hook_array = Array();

    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1, 'suma', 'custom\modulebuilder\builds\Prob\SugarModules\mod ules\b1c2d_Probabilidades\suma.php', 'suma', 'suma');

    parent::save($check_notify);

    return $this->id;
    }
    //to that

    }
    ?>

    But it did not work, how do I do? I'm lost?

    Please, help me

    Thanks a lot

    Joeya

  2. #2
    joeya is offline Senior Member
    Join Date
    Jan 2010
    Location
    Chile
    Posts
    37

    Unhappy Re: Logic Hooks to add fields

    Please please please

  3. #3
    agcopley is offline Sugar Community Member
    Join Date
    Nov 2007
    Location
    Santiago, Chile
    Posts
    204

    Default Re: Logic Hooks to add fields

    Quote Originally Posted by joeya View Post
    Please please please
    Hi joeya,
    There should be no problem in using logic_hooks for custom modules. I have used this multiple times.

    Are you sure you have a file 'logic_hooks.php' in 'custom/modules/<your_module_name>' ?? with something like this

    <?php
    $hook_array['before_save'][] = Array(1, testtype, 'custom/modules/<your_module_name>/<your_file_name>.php', '<your_class_name>', '<your_function_name>');
    ?>

    You would also need a file '<your_file_name>.php' with a class and function that corresponds to the above declaration.

    you should be then able to access the two fields via $bean-field1 etc. to add to your third field. When you save, the third field will show the reults of the calculation.

    Rgds
    Andrew

    p.s If you prefer spanish, I can switch to spanish.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. logic hooks and sql
    By mahmoud07 in forum Developer Help
    Replies: 3
    Last Post: 2010-02-25, 04:29 PM
  2. Logic Hooks
    By Rajesh Patel in forum Help
    Replies: 6
    Last Post: 2009-11-18, 05:57 PM
  3. logic hooks to sync fields
    By imrankha in forum Developer Help
    Replies: 4
    Last Post: 2009-01-30, 10:46 PM
  4. Logic Hooks
    By marketadvantage in forum Developer Help
    Replies: 3
    Last Post: 2009-01-30, 03:09 PM
  5. Custom Fields-do I need to use Logic Hooks??
    By ctaylor2410 in forum Developer Help
    Replies: 2
    Last Post: 2008-10-24, 08:19 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
  •