AnsweredAssumed Answered

Need Help Getting a Custom Relationship Field to Display

Question asked by drifterjack drifterjack on Mar 13, 2015
Latest reply on Dec 19, 2018 by Robert Sinclair
I'm using SugarCRM 7.x. I'm trying to create a custom relationship field. This is not a relate_to field. This is a field that will be updated with the datetime of when the relationship was created. I'll use this field to help determine how many relationships are created for a given time period.

I've been able to add the field and create the logic hook to create the datetime. What I cannot figure out seems to be the same problem that everybody else is getting stuck at.

The problem is that I cannot get the database value to show in the list.

I've surfed the old forum and the new forum to no avail. I assume that I have the variables incorrect and therefore it's not finding things. Here's everything that I have done and learned.

First File

When you add any fields here, they will be created in the database table for your relationship. I have created a field called referred.

    // this will cause the field to be created in the database
    5 =>
    array (
      'name' => 'referred',
      'type' => 'datetime',
Second File

This file shows the fields to list in the subpanel. So anything that I add here creates the column and column title in the subpanel.

  'leads_accounts_1referred' => 
  array (
    'type' => 'datetime',
    'vname' => 'Referred ON',
    'width' => '10%',
    'default' => true,
Wherever you place this array item in the list, so will your column be placed on the subpanel. Again, in order to get this change to show, you need to repair and rebuild.

Third File

In this third file I was instructed, by all of the tutorials, to create three entries. I know that these entries have something to do with the creation of the final queries which will populate the data in the subpanel.

* Explained in
 * This section is copied when you run the quick repair, it is copied from
 * \custom\Extension\modules\Leads\Ext\Vardefs\leads_accounts_1_referred.php to
* \custom\modules\Leads\Ext\Vardefs\vardefs.ext.php

$relation = 'leads_accounts_1';
$relation_field = $relation . '_referred';

// the name of our module, prefix + modulename
$dictionary['Leads']["fields"]["{$relation}_fields"] = array(
    'name' => "{$relation}_fields",
    'rname' => 'id',
    'relationship_fields' =>
        'id' => "{$relation}_id",
        'referred' => $relation_field
//    'vname' => 'LBL_EVENT_NAME',
    'type' => 'relate',
    'link' => 'accounts',
    'link_type' => 'relationship_info',
    'join_link_name' => $relation,
    'source' => 'non-db',
    'Importable' => false,
    'duplicate_merge' => 'disabled',
    'studio' => array('listview' => false),
    'join_name' => $relation.'_c',
    'join_primary' => false,

$dictionary['Leads']["fields"]["{$relation}_id"] = array(
    'name' => "{$relation}_id",
    'type' => 'varchar',
    'source' => 'non-db',
//    'vname' => 'LBL_COURSE_ROLE_ID',

$dictionary['Leads']["fields"][$relation_field] = array(
    'name' => $relation_field,
    'type' => 'datetime',
    'source' => 'non-db',
//    'vname' => 'LBL_COURSE_ROLE',
    'massupdate' => false,

And that's where I'm stuck. I have read nearly every tutorial on how to get this done. Here are the pages that I've read.
This tutorial was created back in 2011. It's focus is to explain how you can create an editable relationship field. Things get a little scrambled in this tutorial and it becomes hard to follow when you're just trying to get one field to show up, non-editable.
This is probably the best tutorial on the old forum. It's a follow along of another developer trying to do this same thing, but it was done in 2009. Very outdated, and anybody that follows it as of late runs into the same problem that I'm having.
This post is from 2010 and it's another follow along of a developer taking a crack at this same problem.
This post was from 2012, it is solved rather quickly by the OP. He does run into the same problem that I have run into and finds his solution by debugging the sql statements.

Steps that I've attempted to Debug this.
  1. I've enabled Developer Mode
  2. I've enabled Debugging Mode
  3. I've searched through everything that I can find in Google, The Old Forum and This New Forum.
I have searched through \include\ListView\ListView.php and found the functions called which are not returning the proper row data.  A function called process_dynamic_listview is the one which is responsible for creating the subpanel view and populating it. This $this->process_dynamic_listview_rows function is called and is the first to show that things are not being queried right.

\data\SugarBean.php is the file with six thousand lines of code that will lead to my answers... if I can first find my problem in here. Seems that those who give up online spend days searching through this file before the find the answer and then disappear without telling the rest of us..

You can help by
1. Providing me with the actual structure for the vardefs file and what each section means and what each section needs to exactly match... That would be nice.

2. Give me the function or line in the SugarBean.php file that will lead to the correct structure for the vardefs file.