Related Field not work

I have to create a common field in leads - meetings

  1. Studio - Leads - Relationships
    Create Relationships 1 one 1 leads - meetings
    result: leads_meetings_1
    1

  2. in custom/Extension/modules/Leads/Ext/Vardefs/data_richiamo.php

<?php
$dictionary['Leads']['fields']['data_richiamo'] = array (
    'name' => 'data_richiamo',
    'vname' => 'LBL_DATA_RICHIAMO',
    'type' => 'datetime',
    'dbType' => 'varchar',
    'len' => 100,
    'audited'=>true,
    'unified_search' => true,
    'merge_filter' => 'enabled',
    'reportable' => '1',
    'importable' => 'true',
  );

3 ) in custom/Extension/modules/Leads/Ext/Language/en_us.data_richiamo.php

 <?php
$mod_strings['LBL_DATA_RICHIAMO'] = 'Data Richiamo';
  1. in custom/Extension/modules/Meetings/Ext/Vardefs/data_richiamo.php
<?php
$dictionary['Meetings']['fields']['leads_meetings_1_name']['join_link_name'] = 'leads_meetings_link';

$dictionary['Meetings']['fields']['data_richiamo'] = array (
		'name' => 'data_richiamo',
		'rname' => 'data_richiamo',
		'id_name' => 'leads_meetings_1leads_ida',
		'vname' => 'LBL_DATA_RICHIAMO',
		'join_name'=>'leads',
		'join_link_name'=>'leads_meetings_link',
		'type' => 'relate',
		'link' => 'leads_meetings_1',
		'table' => 'leads',
		'isnull' => 'true',
		'module' => 'Leads',
		'dbType' => 'varchar',
		'len' => '255',
		'source' => 'non-db',
		'unified_search' => true,
		'massupdate' => false,
		'studio' => array('detailview' => 'true'),
	);
  1. in custom/Extension/modules/Meetings/Ext/Language/en_us.data_richiamo.php
 <?php
$mod_strings['LBL_DATA_RICHIAMO'] = 'Data Richiamo';
  1. REPAIR
    Not work

strange, after creating the 1 one 1 relationship,
in the studio meeting I see the field leads_meetings_1
but I don’t see the same field in the studio meeting

I managed to create the same field in lead and meeting, but the fields are not copied
tips ?
but is it so hard to work with crm suite?
I just have to copy the event start date to listview lead
I’ve been working on it for 10 days
thanks

I thought I had solved copying the field this way

<?php

$dictionary[‘Lead’][‘fields’][‘date_start’] = array (
‘name’ => ‘date_start’,
‘vname’ => ‘LBL_DATE’,
‘type’ => ‘datetimecombo’,
‘dbType’ => ‘varchar’,
‘len’ => 100,
‘audited’=>true,
‘unified_search’ => true,
‘merge_filter’ => ‘enabled’,
‘reportable’ => ‘1’,
‘importable’ => ‘true’,
);

but the date start meeting field and the new date start lead field are not copied

About copy field.
One way. You can use “logic hook” after_save. There is information here https://docs.suitecrm.com/developer/logic-hooks/
You should write the short custom php code and this code will copy from field “date_start” of Meeting to field “date_start” of “Lead”. These modules should have reationship.

Perhaps my mistake is in creating the relationships between modules?
I enter the studio - modules
New realationship
Module events one to one - module lead

this is my procedure

I tried this solution with a personal field, but it didn’t work
try again,
Ralationship one 1 one work ?

hook logico" after_save (not 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;
    }

}

(@prmarketing if you click the “pencil” icon :memo: on your post above, you can see my edit and learn how to enter php code with syntax highlighting)

image

After entering the edit, click the Raw button to see how it is done)

1 Like

You code copy data from field “myfield_c” to field “date_start” of module Lead. You don’t do request to module Meeting. My code for you:

<?php
...
function copy(&$bean, $event, $arguments) {
        $meeting_bean = new Meeting();
        $meeting_bean->retrieve($bean-><field id of relationship with Meeting>);
        $bean->date_start = $meeting_bean->date_start;
    }

sorry,
so I have to create hooks

<?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[‘after_save’] = Array();
$hook_array[‘after_save’][] = Array(1, ‘Value from one field to another’, ‘custom/modules/leads/my.php’, ‘User_hook’,‘copy’);
?>

and my.php

<?php


function copy(&$bean, $event, $arguments) {
$meeting_bean = new Meeting();
$meeting_bean->retrieve($bean->);
$bean->date_start = $meeting_bean->date_start;
}
Blockquote

$bean->date_start = $meeting_bean->date_start;
or
$bean->my_field = $meeting_bean->date_start;

I wrote about hook after_save if you make:

  1. Save Meeting record.
  2. Write date_start from Meeting to Lead.

If you want:

  1. Save Lead record.
  2. Read from Meeting date_start to this Lead.
    you should use before_save.

What is your option?

in lead I write meeting date, I want that date (date_start) to be displayed in my listview
now I try to write you the complete procedure of the code,
do you kindly confirm that it is right?

Clean crm suite installation
latest SuiteCRM-7.11.10 version
START !!
in ftp duplicate field date_start
FTP
custom / module / Leads
I create the logic_hooks.php file

<?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[‘after_save’] = Array();
$hook_array[‘after_save’][] = Array(1, ‘Value from one field to another’, ‘custom/modules/Leads/Leads_Hooks.php’, ‘Leads_Hooks’,‘copyField’);
?>
Blockquote

custom/module/Leads
creo il file Leads_Hooks.php

function copy(&$bean, $event, $arguments) {
$meeting_bean = new Meeting();
$meeting_bean->retrieve($bean->);
$bean->date_start= $meeting_bean->date_start;
}
Blockquote

If you want to write to field “date_start” of Lead object from field “date_start” of Meeting object, you sholud control changing in Meeting module using hook after_save.
Here is the code:
custom/modules/logic_hooks.php

$hook_version = 1; 
$hook_array = Array(); 
$hook_array['after_save'] = Array(); 
$hook_array['after_save'][] = Array(1, '', 'custom/modules/Meetings/my.php', 'User_hook','copy');

custom/modules/Meetings/my.php

class User_hook {
    function copy(&$bean, $event, $arguments) {
        $lead_bean = new Lead();
        $lead_bean->retrieve($bean-><field id of relationship with Lead>);
        $lead_bean->date_start = $bean->date_start;
    }
 }

Change “field id of relationship with Lead” to correct field name. I see name “leads_meetings_1leads_ida” in this conversation.

Thanks, you really have a lot of patience!
Does not work !
I try to explain myself with images, let’s see if I can help you
Thank you so much



using your codes, when I create a lead, it gives me a blank page

I am sorry @prmarketing . I fogot last commad in function copy:

    $lead_bean->save();

:slight_smile:

… wait…i no have Change “field id of relationship with Lead” to correct field name. I see name “leads_meetings_1leads_ida” in this conversation.

There are some problems. Step by step.

  1. At the beginnig of this conversation you wrote that you had made new relationship one-to-one (see file: custom/Extension/modules/Meetings/Ext/Vardefs/data_richiamo.php). I decided that you had inserted this field into editview/quickedit form and you would use id field “leads_meetings_1leads_ida”. But you use system relationship parent_name (screenshot: Meeting quickedit form).

Please @prmarketing , clear which type of relationship you want to use one-to-one or parent_name.

I had deleted everything, now I have created a new one to one relationship
Is it right to get my result?
I changed the code as follows, but when I create a lead I get a blank page

class User_hook {
function copy(&$bean, $event, $arguments) {
$lead_bean = new Lead();
$lead_bean->retrieve($bean-><meetings_leads_1meetings_ida>);
$lead_bean->date_start = $bean->date_start;
$lead_bean->save();
}

} Blockquote

Correct line:

$lead_bean->retrieve($bean->meetings_leads_1meetings_ida);

without: <>

And see comment before.

Please @prmarketing , clear which type of relationship you want to use one-to-one or parent_name.

I don’t understand what you mean, what should I do

i have modify $lead_bean->retrieve($bean->meetings_leads_1meetings_ida);
the lead is blank now

Please @prmarketing , some minuts.