Tracking the very last call result of a contact

Forgive me if I'm posting in the wrong spot!

We have an added custom fields for calls that allow a user to select "TT" for Talk To, "LM" for "Left Message",  "Scheduled Call" and "Ops Note". It helps give us a better idea of which clients are picking up the phone vs not. 

My sales director wants me to provide her a report of all of our current clients and their last call result. (not the last call, but the result. LM, TT, Ops Not, etc) This has proven difficult.

In theory, I think I need to create another field and perhaps a workflow that would occur when the record is saved and update the new field with the newest call result. (I already created a workflow that documents that last phone call date/time stamp but now I need a separate field that shows the last call result)


Does anyone have an idea on how I can accomplish this?

Thank you so much!

Parents Reply Children
  • If you only want to copy a field from e.g. calls to e.g.contacts you can create a logic_hook, which is the easies way to write custom code in Sugar.

    See http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_8.1/Architecture/Logic_Hooks/#Module_Hoo…  for logic_hook documentation.

    The only thing you need is a module hook for module calls.

    So you write a file logic_hooks-php to custom/modules/Calls/  with content like this:

    <?php    
    $hook_version = 1;   
    $hook_array['after_save'][] = array(       
              1,
              'copy code_c to parent contact',
              'custom/modules/Calls/copyCode.php',
              'copyCode',
              'copyCodeFunc',
          );

    Then you create the class module custom/modules/Calls/copyCode.php to execute the code (a simple copy)

    <?php
        class copyCode
        {       
            function copyCodeFunc($bean, $event, $arguments)
            {           
             //logic
                if ($bean->parent_type=="Contacts"){
                   $code = $bean->code_c;
                   $id = $bean->parent_id;
                   $contact = BeanFactory::getBean("Contacts",$id);
                   $contact->code_c = $code;
                   $contact->save();
    //more ...
    //or less
                }
            }   
          }
    ?>

    You can add some additional plausibility check if you want ( e.g $id not empty...).

    If you want to apply it on all participant contacts linked to the call you can add:

    //more ...  
                   foreach ($bean->contacts_arr as $num => $nid){
                      $ncontact = BeanFactory::getBean("Contacts",$nid);
                      $ncontact->code_c = $code;
                      $ncontact->save();
                   }
    //or less

    After Quick Repair and Rebuild the hook should be called and executed

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

  • Hi Harald,

    We don't have prior experience with logic hooks. It kills me that the solution is now staring at my face, yet I'm at a loss as to my next steps. As we aren't on prem, is this something our Sugar Partner would have to implement or can we do this ourselves?

    Thank you! 

  • The developer guide of the current version explains it very detailed.

    So normaly you would engage a partner, but with some training fom Sugar University you can do it yourself too.

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH