AnsweredAssumed Answered

How to create a logic hook in SugarCRM based on info in 'Campaign' subpanel of Leads?

Question asked by Rajneesh Kumar on Jan 17, 2017

I have created a custom field 'eng_sum_c' (decimal type) in Leads.  

 

I also created a tracker based campaign and executed it as sample, and got the email delivered at my email id.  When I click on the URL link (hyperlink), everything goes fine and the behavior is correctly recorded in 'Campaign' subpanel of Lead's DetailView.

 

I know that most of the data presented in 'Campaign' subpanel is obtained from module 'CampaingLog' & 'Campaign' module. For example, Activity Type data is coming from 'CampaignLog' field 'activity_type'.  Related data is coming from 'Campaign' field 'tracker_url'.

 

In Campaign Subpanel, one record has Activity Type = Click-thru (link) and corresponding 'related' which is a URL (tracker).

Campaign Subpanel

I want to create a logic hook for leads module, which if possibly, could use both pieces of information as conditions on each occurrence of:

if Activity Type = Click-thru (link) and other 'related' = , then the incremental value is added to custom field 'eng_sum_c'.

I have tired to create a logic hook for this in folder: custom/modules/CampaignLog, and the logic_hook.php contains the following instruction:

<?php

$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1, 'Eng Score via CampaignLogs', 'custom/modules/CampaignLogs/ENGScoring.php', 'SUM', 'ENGScore');
?>

 

And I attempted to build the logic in ENGScoring.php:

<?php

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

class SUM
{
    function ENGScore($bean, $event, $arguments)
    {
        if ($bean->target_type == "Leads" && $bean->activity_type == "link" && $bean->related_type == "CampaignTrackers")
        {
           $CampaignTracker = BeanFactory::getBean('CampaignTracker', $bean->related_id);
           $TrackerUrl = BeanFactory::getBean('Campaign', $bean->tracker_url);
           if ($CampaignTracker && $TrackerUrl === "https://community.sugarcrm.com/community/developer/content?filterID=contentstatus%5Bpublished%5D~category%5Blogic-hooks%5D")
            {
               $lead = BeanFactory::getBean('Lead', $bean->target_id);
               $lead->eng_sum_c = '55';
               $lead->save();
            }           
    }
}

 

But nothing seems to work and no value is added to field 'eng_sum_c'.

How such logic hook can be created?

Your helping hand is solicited!

With thanks,

RK

There are some pieces of information which may be helpful:

  1. This 'Campaign' Subpanel is getting most data from module: CampaignLog (which has a relationship with Campaign). [Corresponding MySQL Table: campaign_log]
  2. However, tracker_url data is obtained from Campaing [Corresponding MySQL Table: campaign]
  3. These variables are defined in vardefs.php of sugarcrm>modules>CampaignLog> Vardefs>

Outcomes