How to save a custom field after a log call

Hi,
I have a custom field on my lead table that I would like to update anytime a user save a new log call.

I have been trying to look the code in call.php and CallFormBase.php, I get that I should change something in the function call() but I dont really understand where/what is the real function called when the user click save.

I think I should do something like:
$MyField = new Call();
$MyField->retrieve(‘my lead id’);
$MyField->Touch_Phone = ‘1’;
$MyField->save();

I’m all new on this CRM, thank you for your help!

Hi,
not sure with workflow …i give the direction :

first workflow

  • create workflow for call module
  • for all record, or new record, for save or modified…
  • action, record type lead … action update your custon field
    Not sure when the workflow is fired, after save, after relationship add (very important)

second logic hook (you must work on call module)

  • you must distinct new or modified record (this is the real “must to know” )
  • the sample you provide is bad, is not “new Call” but it must be “new Lead”
    i dont know if you can retreive ID of lead relationship, maybe you must in logic hook load relationship.

If you understand, the problem is retrieve the related id of lead (relate field ou many to … is not same).
You don’t have this id for new record call, the call is saved in database (for have a id) and then the call is saved and related in table leads_calls with the id of call. !

For more tips, search in forumt with “item” .

Regards

Thank you, since the field is calculated (increment) I can’t use a worflow :confused:

Would it works if I create a function in Call.php:
function increment_phone()
{
$query = “SELECT touches_phone_c from leads_cstm where id_c=’$this->lead_id’”;
$result = $this->db->limitQuery($query,0,1,true," Error filling in additional detail fields: ");
$new_NbCall = $result + 1;
$db -> query(“update leads set touches_phone_c = ‘$new_NbCall’ where id_c = ‘$this->lead_id’”);

	}

and then I’m calling it when the call is saved (in CallFormBase.php, not sure where… though)

HI,
I think this sample code must do your requirement.

In Leads module, create custom logic hook
Check if the related module is “Calls”
If yes, do a SQL query

count all related call, “select count() from calls_leads where delete=0 and lead_id =” then make a update.

For be more complete, do the same with logic hook after_relationship_delete

Regards


<?php

if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('modules/Contacts/Contact.php');
require_once('modules/DIO_Fonctions/DIO_Fonctions.php');

class contacts_after_relationship_add
{	
	function after_relationship_add(&$bean, $event, $arguments)
	{
		if ($event != 'after_relationship_add') return;

        if ($arguments['module'] == "Contacts" && $arguments['related_module'] == "DIO_Fonctions"){
			$fonction = BeanFactory::getBean($arguments['related_module'], $arguments['related_id']);
			if ($fonction->id){
				$bean->assistant_phone = $fonction->name;
				$bean->dio_fonction_id = $fonction->id;			
			}
        }
        
        
		/*
        if ($arguments['module'] == "Contacts" && $arguments['related_module'] == "Accounts"){
			//$fonction = BeanFactory::getBean($arguments['related_module'], $arguments['related_id']);
			if ($bean->dio_nomenclature){
        	$sQuery = "UPDATE accounts_contacts_1_c 
        				SET accounts_contacts_short_nom='".$bean->dio_nomenclature ."',
        				accounts_contacts_fonction_id='".$bean->dio_fonction_id ."'  
        				WHERE deleted=0 AND dio_nomenclature=' ' AND id='" .$_REQUEST['child_id'] ."'";
        	$GLOBALS['db']->query($sQuery, true);
        	}	  
        }
        */
		
	}
	
}

?>

1 Like

Thanks, where should I write this query and the update? on Lead.php in modules?
Also do I create a logic hook from the CRM itself or it has to be a new php file?