AnsweredAssumed Answered

Copy Date from One module to another

Question asked by jay jay on Apr 24, 2015
Latest reply on Apr 27, 2015 by Rolustech Rolustech
Sugar Version CE 6.5.20 (Build 1001)

I have 2 custom modules One is called Members and the other is called Attendance. Their table names are dsc_members and dsc_attendance.

In Members I have a field called enddate and I need to show the values of this date field in attendance. I have a one to many relationship setup between members and attendance.

I followed the tutorial http://developer.sugarcrm.com/2012/03/13/howto-grab-fields-from-a-related-record-without-sugar-logic...  - this works but my problem is it just adds it into a text field and not a date field. Also it displays it in the format as yyyy/mm/dd ( I believe this is the mysql format ).

So in studio I created a date field called attenddate in Attendance. I need attenddate from Attendance Module and the enddate from Members module to be the same. I reallly only need to see this from Listview  and I want it read only.

Im try to follow a tutorial for a non-db field but I need to do this for DB field as I've explained above about the date field.

Here is my logic_hooks.php

<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['after_retrieve'] = Array();
$hook_array['after_retrieve'][] = Array(1, 'AfterRetrieve', 'custom/modules/dsc_Attendance/CustomLogicHooks.php','CustomLogicHooks', 'afterRetrieve');
$hook_array['process_record'] = Array();
$hook_array['process_record'][] = Array(1, 'ProcessRecord', 'custom/modules/dsc_Attendance/CustomLogicHooks.php','CustomLogicHooks', 'processRecord');
here is my CustomLogicHooks.php 

<?php
class CustomLogicHooks {
    // Load Contact Office Phone into non-db field on Calls
    function afterRetrieve(&$focus, $event, $arguments) {
        if (empty($focus->fetched_row['attenddate'])) {
            $link = "dsc_members_dsc_attendance";
            if ($focus->load_relationship($link)) {
                $dsc_members = $focus->$link->getBeans();
                $parentBean = false;
                if (!empty($dsc_members)) {
                    reset($dsc_members);
                    $dsc_member = current($dsc_members);
                    // $dsc_members->custom_fields->retrieve(); // Use this if the Contact field is a custom field
                    $focus->attenddate = $dsc_members->enddate;
                }
            }
        }
    }
    function processRecord(&$focus, $event, $arguments) {
        afterRetrieve($focus, $event, $arguments);
    }
}

When using this the Attendance Module Shows up empty

Outcomes