Thursday, October 8, 2009

Fix "Related To" problem in Sugar Notes module

We have a customized module "Installation" in Sugar. It related to Notes module. For some reason, when user create a note from Installation module, it doesn't automatically pull out the related Installation record. As a matter of fact, in "related to" field, "Installation" is not even an option.

I know a Dropdown named "parent_type_display", I add Installation into there, but it works for any other activities, such as Call, Meeting.. except Notes.

Then I decided to trace it from the code. I started from index.php, then I found out it is a long trip to reach the problem. I only care about final display, so if the dropdown options is not from "parent_type_display", then it must be somewhere to generate the select options. I need to find how the final html is generated. Then I find file include/EditView/EditView2.php, and it has a method display(). I believe this should be the last method to generate the html stream. I put a log right before the statement
$str .= $this->th->displayTemplate($this->module, $this->view, $this->tpl, $ajaxSave, $this->defs);

Then assumption is approved. This string is the final html. Then I went a step further, dig into method displayTemplate() in file include/TemplateHandler/TemplateHandler.php.

Hmm, it's the place to find what is the final template file. I put a log statement right after :
$file = $this->cacheDir . $this->templateDir . $module . '/' . $view . '.tpl';
$GLOBAL['log']->debug("template file name : ".$file);

I found out the template file is catch/modules/Notes/editview.tpl. Then I open this file, search for "select". found this:
{html_options options=$fields.parent_name.options selected=$fields.parent_type.value}

I know fields is an array defined in modules/Notes/vardefs.php, open that file, I see this:
 'parent_name'={
     array(
        'name'=> 'parent_name',
        'parent_type'=>'record_type_display' ,
        'type_name'=>'parent_type',
        'id_name'=>'parent_id', 'vname'=>'LBL_RELATED_TO',
        'type'=>'parent',
        'source'=>'non-db',
        'options'=> 'record_type_display_notes',
        ),

Here it is, the dropdown is not "parent_type_display", I check other module's definition, such as "meetings, calls", they all use "parent_type_display". That's why change this dropdown values, "related to" can be changed for other module except Notes.

Then I goto Dropdown Editor, add my customized module name into "record_type_display_notes". Problem solved.


1 comment:

Jerzy SzymaƄski said...

There is another dropdown for relating Emails:

'record_type_display'

Google+