Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Logic Hook to auto-populate custom field

  1. #1
    nigel_john Guest

    Default Logic Hook to auto-populate custom field

    Hi,

    I have a custom field in Leads module - data type (relate). Name of the field is 'referred by'
    So, if Lead A refers Lead B, then when creating Lead B I manually select Lead A in 'referred by' field.

    I have created another field 'referrals' in Leads module
    What I want is when I "detail view" Lead A I need to to see Lead B in the 'referrals' field of Lead A; that needs to be auto-populated.
    I've tried relationships - many-to-many; but I am presuming I need a logic hook here.

    Thanks in advance.

  2. #2
    ganoes is offline Sugar Community Member
    Join Date
    Sep 2011
    Posts
    15

    Default Re: Logic Hook to auto-populate custom field

    Hi,

    The relate type field does not quite create a relationship, so it may be difficult to use it as such.

    For a simpler and quicker solution, you could create a one-to-many relationship between Leads module and Leads module and use the generated subpanel to see the referrals, just changing labels for fields and Subpanel (from Leads to Referals).

    With the logic hook approach, in an after save logic hook you could try to query the DB by something like SELECT id,first_name,last_name FROM leads l INNER JOIN leads_cstm lc ON l.id=lc.id_c WHERE lc.lead_id_c = $bean->id.
    Mind the exact name of the custom field the relate field creates lead_id_c (or something similar) - you can find it easily by looking in cache->modules->leads->Leadvardefs.php or look it up in the DB if you have access to it. With this information you can create a list of leads by iterating through the resulting array (if there is more than one result) and enter it into the referrals field.

    Hope it helps a bit.
    GL

  3. #3
    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

    If I follow you correctly, and you created a M-N relationship between Leads module and itself then you should see a subpanel with the referrals.
    So if Lead A refers Lead B, Lead B should be listed in the subpanel on Lead A.
    Francesca
    =========
    SugarCRM Professional 6.5.15
    Linux
    Apache
    MySql
    PhP

  4. #4
    Editha is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    68

    Default Re: Logic Hook to auto-populate custom field

    that seams to be a one-to-many Relationship. Then you can see in a subpanel of the DetailView of Lead A all Leads, which have been reffered by Lead A.

    You could also do it by a LogicHook 'after_retrieve' for the Leads DetailView. In the Hook you have to select all Leads reffered by the retrieved Lead and to put them into the non-db-field 'refferals'.

  5. #5
    nigel_john Guest

    Default Re: Logic Hook to auto-populate custom field

    Thanks guys for the pointers, but the Relationship way don't work.
    I'm attaching screen-shots for a clearer picture.Name:  Referral field.png
Views: 507
Size:  10.2 KBName:  Referral rel.png
Views: 493
Size:  9.0 KBName:  Referral sub.png
Views: 514
Size:  26.7 KBName:  Lead referral.png
Views: 537
Size:  31.0 KB

  6. #6
    nigel_john Guest

    Default Re: Logic Hook to auto-populate custom field

    Thanks so much guys but the relationship thing don't work.
    I'm attaching screen-shots for a clearer picture.

    Thanx in advance.
    Attached Images Attached Images     

  7. #7
    nigel_john Guest

    Default Re: Logic Hook to auto-populate custom field

    Thanks guys but the relationship sub-panel don't work. I'm not able to attach screen-shots.
    I do get a sub-panel Labled as 'referral' but it contains no data.

  8. #8
    Editha is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    68

    Default Re: Logic Hook to auto-populate custom field

    "I do get a sub-panel Labled as 'referral' but it contains no data."

    Did you insert a referred by? The Referred By field in the Edit/DetailView is the left side of the relationship with label 'Leads', you can change the label.

    Name:  leads.png
Views: 514
Size:  39.8 KB

    The label of the left side in the language files under custom/modules/Leads/language/
    $mod_strings = array (
    'LBL_LEADS_LEADS_1_FROM_LEADS_L_TITLE' => 'Referred by',

  9. #9
    nigel_john Guest

    Default Re: Logic Hook to auto-populate custom field

    Thanks Editha, but still no joy.

    en_us.lang.php

    $mod_strings = array (
    'LBL_ASSIGNED_TO_NAME' => 'Lead Owner',
    'LBL_ASSIGNED_TO' => 'Lead Owner',
    'LBL_REFERREDBY_LEAD_LEAD_ID' => 'Referred By (L) (related Lead ID)',
    'LBL_REFERREDBY_LEAD' => 'Referred By (L)',
    'LBL_REFERED_BY' => 'Referred By:',
    'LBL_LEADS_LEADS_1_FROM_LEADS_L_TITLE' => 'Referred By (L)',
    'LBL_LEADS_LEADS_1_FROM_LEADS_R_TITLE' => 'Refferal',
    );

    Attaching scree-shots for a clearer picture.Name:  Lead Ref by.png
Views: 471
Size:  21.8 KBName:  Lead referral.png
Views: 468
Size:  29.6 KBName:  Lead relate.png
Views: 460
Size:  9.6 KBName:  Lead subpanel.png
Views: 477
Size:  27.7 KBName:  Ref by field.png
Views: 468
Size:  9.9 KB

  10. #10
    ganoes is offline Sugar Community Member
    Join Date
    Sep 2011
    Posts
    15

    Default Re: Logic Hook to auto-populate custom field

    Hello Nigel,

    There is still a confusion between relationships and the Relate data type field in Studio.

    The relate data type field does not create a relationship in SugarCRM. It should be used only for trivial things if at all (i would say never).

    So you either delete it and follow Editha's instructions for working with the Leads_Leads O2M relationship, or if you want to keep it, write the logic hook described in my first post, but be aware that you will be working much more and at some point you will inevitably feel the limitation of the Relate type field.

    Best of luck!

Page 1 of 2 12 LastLast

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
  •