Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Logic Hook to auto-populate custom field

  1. #11
    nigel_john Guest

    Default Re: Logic Hook to auto-populate custom field

    Awesome. Got it. I was adding "referred by" in a new field, when I need to select it in "leads"
    Thanks a TON guys.

    However can I change the "Leads" label to "Referrals" or something likewise?
    If not I'd like to go the logic hook way. I'll post the files once I work on them.

    Once again you'll are the best!


    Name:  Ref by.png
Views: 107
Size:  20.3 KBName:  Referral Final.png
Views: 115
Size:  29.9 KB

  2. #12
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: Logic Hook to auto-populate custom field

    U can rename LABEL in studio - find related LABEL in label list - then save and deploy
    or u can change label name in custom/include/language/your_lang.php
    to get label name you can use firebug extension or something like that

  3. #13
    nigel_john Guest

    Default Re: Logic Hook to auto-populate custom field

    Hey Guys, I was able to create the logic hook:

    ================================================== ================================================== ======================
    <?php

    // custom/modules/Leads/Leads_ReferralHook.php

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

    class Leads_ReferralHook {

    function mapreferral(&$bean, $event, $arguments) {
    $GLOBALS['log']->debug("Made it to Leads_referral_hook file");
    global $locale;
    // after_retrieve
    $query = "SELECT salutation,first_name,last_name FROM leads INNER JOIN leads_cstm ON leads.id=leads_cstm.id_c WHERE leads_cstm.lead_id_c = '".$bean->id."' AND deleted=0";
    $result = $bean->db->query($query,true);
    $row = $bean->db->fetchByAssoc($result);
    $bean->refferal_c = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
    }
    }
    ================================================== ================================================== ======================

    However, as expected, I get only first matching row.

    I then tried this:
    ================================================== ================================================== ======================
    <?php

    // custom/modules/Leads/Leads_ReferralHook.php

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

    class Leads_ReferralHook {

    function mapreferral(&$bean, $event, $arguments) {
    $GLOBALS['log']->debug("Made it to Leads_referral_hook file");
    global $locale;
    // after_retrieve
    $query = "SELECT salutation,first_name,last_name FROM leads INNER JOIN leads_cstm ON leads.id=leads_cstm.id_c WHERE leads_cstm.lead_id_c = '".$bean->id."' AND deleted=0";
    $result = $bean->db->query($query,true);
    $mutipleLeads = array();
    $i=0;
    while (($row=$bean->db->fetchByAssoc($result)) != null) {
    $mutipleLeads[$i] = $row;
    $i++;
    }
    $row = $bean->db->fetchByAssoc($result);
    $bean->refferal_c = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
    }
    }

    ================================================== ================================================== ======================


    But then nothing shows up.

    Thanks in advance for all the help.

  4. #14
    nigel_john Guest

    Default Re: Logic Hook to auto-populate custom field

    Any insights as to how I can get all records?

  5. #15
    nigel_john Guest

    Default Re: Logic Hook to auto-populate custom field

    Hey Guys, I got it work...somewhat...

    ================================================== ================================================== ======================
    <?php

    // custom/modules/Leads/Leads_ReferralHook.php

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

    class Leads_ReferralHook {

    function mapreferral(&$bean, $event, $arguments) {
    $GLOBALS['log']->debug("Made it to Leads_referral_hook file");
    global $locale;
    // after_retrieve
    $query = "SELECT salutation,first_name,last_name FROM leads INNER JOIN leads_cstm ON leads.id=leads_cstm.id_c WHERE leads_cstm.lead_id_c = '".$bean->id."' AND deleted=0";
    $GLOBALS['log']->debug($query);
    $result = $bean->db->query($query,true);
    while($row = $bean->db->fetchByAssoc($result)){
    $bean->refferal_c .= $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
    }
    }
    }
    ================================================== ================================================== ========================

    But there is no space or delimiter between the records.
    Any help is appreciated.
    Thanks in advance.


    Name:  Referral.png
Views: 88
Size:  21.0 KB

  6. #16
    Francescas's Avatar
    Francescas is offline Sugar Community Member
    Join Date
    Dec 2011
    Location
    Colorado
    Posts
    508

    Default Re: Logic Hook to auto-populate custom field

    You could try using beans instead of sql
    PHP Code:
    function mapreferral(&$bean$event$arguments) {
       
    $lead = new Lead();
       
    $where "lead.lead_id_c = '$bean->id' ";
       
    $referrals_list $lead->get_full_list('lead.id'$where); //finds referrals ordered by lead.id
       
    if (!empty($referrals_list)){
          
    $all_referrals = array();
          foreach(
    $referrals as $ref){
             
    $all_referrals[]= $ref->first_name ',' $ref->last_name
          }
       }

    The get_full_list function is defined in data/SugarBean.php

    HTH
    Francesca
    Francesca
    =========
    SugarCRM Professional 6.5.15
    Linux
    Apache
    MySql
    PhP

  7. #17
    nigel_john Guest

    Default Re: Logic Hook to auto-populate custom field

    Awesome. That did it.
    Thank you so much all.

Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 19
    Last Post: 2013-11-11, 08:15 AM
  2. Replies: 0
    Last Post: 2011-01-23, 09:52 AM
  3. Replies: 3
    Last Post: 2010-04-27, 11:59 PM
  4. Accessing custom field in logic hook
    By rickbraley in forum Developer Help
    Replies: 1
    Last Post: 2010-01-30, 11:48 AM
  5. Custom field auto increased by Logic Hook ?
    By dekleinemedia in forum Help
    Replies: 21
    Last Post: 2009-07-06, 10:10 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
  •