Copy related field to other field

I am trying to copy the contents of a related field to a text field. See Image below

I tried it with a workflow but ended up with below. It does actully bring up the correct entry but I need it to show same name.

Hi,

You can use the before save logic_hook.

I never used Logic hooks could you give me an example?

I am trying to get this to work could someone give me a hand with it. My logic_hooks.php looks like below.

 <?php
// Do not store anything in this file that is not part of the array or the hook version.  This file will	
// be automatically rebuilt in the future. 
 $hook_version = 1; 
$hook_array = Array(); 
// position, file, function 
$hook_array['before_save'] = Array(); 
$hook_array['before_save'][] = Array(1, 'Value from one field to another', 'custom/modules/ship_Membership/my.php', 'User_hook','copy');



?>  

my.php looks like below

 class User_hook {

    function copy(&$bean, $event, $arguments)
    {

    $bean->name  = $bean->member;
    }

}     

here is the error i get on save

class User_hook { function copy(&$bean, $event, $arguments) { $bean->name = $bean->member; } }

Hi Jay,

Your codes seems correct, it should work.

Can you please confirm that field $bean->member is correct, also please post whole error, so We can identify the issue.

Thanks,

please help me it’s 7 days that i hit my head with this topic

I want to copy the event start date (DATE_START ') into a custom field.
my logichook is this but it doesn’t work:

 <?php
// Do not store anything in this file that is not part of the array or the hook version.  This file will	
// be automatically rebuilt in the future. 
 $hook_version = 1; 
$hook_array = Array(); 
// position, file, function 
$hook_array['before_save'] = Array(); 
$hook_array['before_save'][] = Array(1, 'Value from one field to another', 'custom/modules/leads/my.php', 'User_hook','copy');
?>  

my.php

 class User_hook {

    function copy(&$bean, $event, $arguments)
    {

    $bean->date_start  = $bean->myfield_c;
    }

}

If you want to copy the Event Start Date to your Custom field “myfield_c”, then this logic is wrong.

use it like
$bean->myfield_c = $bean->date_start;

thank cherub… but dont work

What is your Custom Field Type? Can you share the vardef definition of ‘myfield_c’ ?

If you log the Bean, with statement $GLOBALS['log']->fatal(print_r($bean,1)); do you see any value in the date_start field?

sorry what you mean with
kind of field?
Datetime

i have add $GLOBALS[‘log’]->fatal(print_r($bean,1));
nothing value

The path for the File my.php is custom/modules/leads/my.php which doesn’t get recognised as the Folder should be named Leads with a Capital L
Change that in the hooks file too.

$hook_array['before_save'][] = Array(1, 'Value from one field to another', 'custom/modules/Leads/my.php', 'User_hook','copy');

// created: 2019-12-07 18:37:07
$dictionary[‘Lead’][‘fields’][‘lucadc_c’][‘inline_edit’]=‘1’;
$dictionary[‘Lead’][‘fields’][‘lucadc_c’][‘labelValue’]=‘lucadc’;

but now … open windows whit message undefinited

I fixed everything, I also write the routes

custom/modules/Leads/Ext/LogicHooks/logichooks.ext.php

<?php //WARNING: The contents of this file are auto-generated $hook_array['before_save'][] = Array(1, 'Value from one field to another', 'custom/modules/Leads/my.php', 'User_hook','copy'); ?>

custom/modules/Leads/my.php

<?php class User_hook { function copy(&$bean, $event, $arguments) { $bean->lucadc_c = $bean->date_start; } } }

this works for me, but we’re not in the right modules !!
How can I make it work in Events-date_start listview leads?
thank

reate a field as last_activate_date in Targets module or your module through Admin > Studio > Targets > Fields.

It will created in prospects_cstm table as last_activity_date_c.

Add the code in custom/modules/Tasks/logic_hooks.php. If logic_hooks.php doesn’t exit create logic_hook.php.

$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(
    78,
    'Retrieve and compare values',
    'custom/modules/Tasks/lastActiveDate.php',
    'lastActiveDate',
    'after_save_method'
);

Then create lastActiveDate.php and add the following code:

Class name and file name must be same.

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

    function after_save_method($bean, $event, $arguments)
    {
        $module=$bean->parent_type;
        $record_id=$bean->parent_id;
        $bean1 = BeanFactory::getBean($module, $record_id);
        $tblname = $bean1->table_name;
        $tblname_cstm = $tblname."_cstm";
        $bean->db->query("UPDATE ".$tblname_cstm." SET last_activity_date_c=now() WHERE id_c='".$bean1->id."'");
    }
}

last activities date and time will stored in last_activity_date_c feild, while creating and modifying the Tasks.

as required use:
SuiteCRM-7:11:10
Centos 7
PHP 7.3.11
thank you all

Write the Hooks definition in
custom/modules/Leads/logic_hooks.php
and point to the Correct File in the Hook Definition.

<?php
// Do not store anything in this file that is not part of the array or the hook version.  This file will	
// be automatically rebuilt in the future. 
 $hook_version = 1; 
$hook_array = Array(); 
// position, file, function 
$hook_array['before_save'] = Array(); 
$hook_array['before_save'][] = Array(1, 'Value from one field to another', 'custom/modules/Leads/Leads_Hooks.php', 'Leads_Hooks','copyField');
?>  

your hooks file Leads_Hooks.php might look like

<?php 
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  class  Leads_Hooks { 

      function copyField(&$bean, $event, $arguments) { 
          $bean->lucadc_c = $bean->date_start; 
       }
}

cherub thank for you reply
i have insert you new code, but i insert a new lead have a blank page…

this is other question…
the logic_hooks.php e my.php

must be entered in custom / Leads (arrival field)
or
custom / FP_events (starting field)

I saw that date_start is a general field for many modules (calls, emails, …)
I don’t have to enter some conditions to take the specific date_start events field

thanks

If you need Top level logic hook, you can put your definition at
custom/modules/logic_hooks.php

Your requirements seems to vary. What exactly you want to do.

Updates
I entered a new field
$ bean-> last_c = $ bean-> last_name;
This field works
Now I think the problem is that
$ bean-> lucadc_c = $ bean-> date_start;
date_start belongs to an external module (events) is also present in the sub-panel (event1)

I am also attaching the screen of what I want to do


please, any suggestions?

thanks