Related Field not work

(@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.

@prmarketing How do you configure your suitecrm?

  1. You use Studio.
  2. Edit php files.

I use studio is simple for me, i have creare date_start field lead whit php

@prmarketing It’s good the comment. Because.

  1. If you use Studio all field have “_c” in end of field name.
  2. If you edit files you can use any name.

I made code and tested it for you.
Please, step by step:

  1. Delete you relationship one-to-one.
  2. Delete field “date_start” in Lead module.
  3. Make “date_start” in Lead module using Studio.
  4. Use the code:
class User_hook {
    function copy(&$bean, $event, $arguments) {
        if ($bean->parent_type=='Leads'){
            $lead_bean = new Lead();
            $lead_bean->retrieve($bean->parent_id);
            $lead_bean->date_start_c = $bean->date_start;
            $lead_bean->save();
        }
    }
 }

3 Likes

you are great
I have no words to define you !!!
Thanks thanks thanks

if it is not difficult, I can ask you one last thing, since you are so kind and prepared
How can I make LBL_DATE_START
event today: red color
expired event: color …
future event: color

OK. I know decision. I write some late and I be ready for you answer tomorrow.

Decision for you @prmarketing :

  1. Edit file:
    custom/Extension/modules/Leads/Ext/Vardefs/_override_sugarfield_date_start_c.php
  2. Add line:
$dictionary['Lead']['fields']['date_start_c']['function']=array('name' => 'dateStart', 'returns' => 'html', 'onListView' => 'true', 'include' => 'custom/modules/Leads/custom_field_html.php');
  1. Make and edit file:
    custom/modules/Leads/custom_field_html.php
  2. Add code:
<?php
function dateStart($focus, $field, $value, $view){
    $late="#0E44CC";
    $early="#5E9902";
    $today="#FF3609";
    if($view==="ListView"){
        global $timedate;
        $delta = $timedate->fromUser($value)->format("Ymd") - $timedate->getNow()->format("Ymd");
        if ($delta > 0){
            $color=$early;
        }else{    
            if ($delta < 0){
                $color=$late;
            } else{
                $color=$today;
            }
        }
        return "<b style='color:".$color."'>".$value."<b>";
    }
}
  1. Go to Admin->Repair->Quick Repair and Rebuild
  2. See ListView of Lead

Please remember if you change the field ‘date_start’ of Lead in Studio you lost addition line (point 2). You can add the line again but don’t fogett to make “Quick Repair and Rebuild”.

2 Likes