UPDATE:
I have been unable to get the other suggested ways (in this thread) to work so I have been using the fix that I outline in this thread for different modules. If anyone need an installable sugar module that allows you to install this hack for SugarCrm versions 5.0.0, 5.0.0a, 5.0.0b, 5.0.0c and 5.0.0e they can be found here (https://sourceforge.net/project/show...roup_id=210096). There are also some other modules that might be of interest.
NOTE: This post describes how to hack the Sugar core code to add a relative uniform way of allowing related module info to be displayed with a link in the subpanel. This code change is rather simple and should not contain any errors however please use at your own risk and please test it on a development system before taking it anywere close to a live system. This posting is AS-IS with no liability, guarantees, yada, yada, yada (you know the drill).
Any feedback on that the HACK is not necessarily will be very welcome. Any feedback what the cleanest official solution for this would also be very welcome. I am pretty unhappy with the core hack.
I will also describe how to do this hack.
I have used some time to try to avoid this hack but in the end after several deep debugging sessions I had to give up. I could not find the needed infrastructure there. I am sure it is there somewhere and I am just missing it. If there is any Sugar gurus out there that would care to comment so I do not lead anyone astray with this post please feel free?
Goal: I would try to use the existing infrastructure in Sugar to do this subpanel relation for me. There is a ton of options in the different def files around the place. I would go rather far to not do any SQL whatsoever even though a way have been described here (http://dl.sugarforge.org/sugardocs/N...on/Vardefs.pdf on page 4 and 5). However I chose to try get by with the definition files only and no direct SQL.
First of all we (to my knowledge) need the hack.
In SugarCrm 5.0 Full Release /data/SugarBean.php we need 2 changes:
Change #1
In line 2996 change the line from
$ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.' . $data['rname'] . ' ' . $field;
to
$ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.' . $data['rname'] . ' `' . $field . '`';
(This change is only included so the automatic subpanel select can handle weird column aliases like "case" (module Cases) so Sugar automatically can assign the value from the database to the correct field defined in the vardef. One could argue that this is not a hack but rather improving on the already existing code, since this will make the existing code more robust. If the field name in the vardef (specified in the modules builder) is a reserved Mysql word, then this could throw a mysql error. So maybe you could even call it a bug fix. This should probably be done in all the SQL generating statements, but I will leave that up to Sugars judgment. )
Change #2
After line 3009 please paste the following:
if(isset($value['related_record_key']) && !empty($filter))
{
$ret_array['select'] .= " , {$params['join_table_alias']}.{$value['related_record_key']} as {$value['target_record_key']}";
}
(this adds support for a new named array field for the /modules/SOMEMODULE/metadata/subpanels/default.php the "related_record_key". I could not get any of the different sql statement generating options in SugarBean.php to do what I wanted.)
Now the only file that needs to be changed to support this functionality is:
/modules/SOMEMODULE/vardefs.php
/modules/SOMEMODULE/metadata/subpanel/default.php (or some other file if you have defined them)
I have attached an example from one working module that is using this technique. See post #2 for a more tutorial like post
STEPS TO VISUALIZE - how this hack implements a missing functionality in the current SugarCrm implementation.
With the rich metadata interface that Sugar has I would prefer configuration over code anytime. And ultimately this should have support in Studio and ModuleBuilder.
Sugar ModuleBuilder rocks and is very good, but currently if you use ModuleBuilder to edit subpanels then if you drag-n-drop a "relate" field to the subpanel then that field will not show any data when the subpanel is shown. That is either a bug or missing implementation. If the GUI allows drag and drop field on a subpanel then IMHO it is also expected to be able to handle this in view mode.
Steps to reproduce
1. Go Admin / ModuleBuilder
2. Create new package "test"
3. New Basic module "test"
4. Add a new field called "case"
5. Add a relationship to Leads, Label="Leads"
6. Edit the Available subpanels and include the field "case" in this subpanel
7. Save
8. Edit the EditView, Listview and Detailview to also include the "case" field.
9. Deploy
10. Quick Rebuild
11. Go to Leads
12. Select a lead
13. Go to test subpanel
14. Create new test and relate to a case
15. Save
16. In my version there is no data in the subpanel for the field case.
UPDATE: The "OUTSTANDING ISSUES" is no longer relevant due to SugarCrm patch 5.0.0a.
OUTSTANDING ISSUES:
The LEFT OUTER JOIN that is created automatically should in my opinion need a where clause filtering on the parent id to return to correct rows, I have not had time to investigate this further right now, but will look into it. It seems to be working as is though.
UPDATE:
This is the sql that is generated from a entity that has 3 relate fields.
SELECT resource_allocation.id,
resource_allocation.start_date,
resource_allocation.end_date,
resource_allocation.hard_booking,
jt0.name `project`,
resource_allocation.project_id,
jt0.id as project_id,
jt0.assigned_user_id project_owner,
'Project' project_mod,
jt1.name `bug`,
resource_allocation.bug_id,
jt1.id as bug_id,
jt1.assigned_user_id bug_owner,
'Bugs' bug_mod,
jt2.name `case`,
resource_allocation.acase_id,
jt2.id as acase_id,
jt2.assigned_user_id case_owner,
'Cases' case_mod,
resource_allocation.assigned_user_id,
'resource_allocation' panel_name
FROM resource_allocation ´
LEFT JOIN project jt0 ON jt0.id= resource_allocation.project_id AND jt0.deleted=0 AND jt0.deleted=0
LEFT JOIN bugs jt1 ON jt1.id= resource_allocation.bug_id AND jt1.deleted=0 AND jt1.deleted=0
LEFT JOIN cases jt2 ON jt2.id= resource_allocation.acase_id AND jt2.deleted=0 AND jt2.deleted=0
where resource_allocation.deleted=0
There are a few sub optimal things with this query.
1. For each LEFT JOIN there are 2 "AND jt0.deleted=0 AND jt0.deleted=0 "
2. The LEFT JOIN will cause all rows from the resource_allocation table to be fetched this will in turn end up returning potentially quite a few rows. Over time in this scenario a resource (i.e. a management consultant) can be assigned to many allocations during a year, maybe hundreds if allocations are short. This will cause a big amount of data.
The more relate fields you have and want to show in a subpanel the bigger this problem becomes.
Any ideas on how to fix this?


LinkBack URL
About LinkBacks
.
. This should probably be done in all the SQL generating statements, but I will leave that up to Sugars judgment. )



Reply With Quote

Bookmarks