Skip to main content

How to Create a sub-panel and build relationships

How to Create a sub-panel and build relationships on the
modules Oqc-Contract, oqc-Offering, oqc_products.

Attention: Every time you need to make a change like this it's smart to backup the files to be
modified and a backup the database. It must not be done when there are users on-line on the
system.
The module of OpenQuotesandContracts, can be downloaded at the site of sugarforge
in projects, the modules were developed to work with mozzila. This manual will explainain
how to create relationship with other modules, also create the sub-panels of these
relationships. All customizations are not Upgrade-SAFE, or if made some customization the
set up files, should be kept to verify the possibility of having integration with other future
versions of sugarCRM.
Many to many relationships on sugar CRM are made with some steps.
- Define the link of relationship on the vardefs of both modules on the relationship
- Create a metadata file with the fields of DB and definition of the relationship
- Set up the database table
- Create Subpanels
VARDEFS
On vardefs file of the modules is necessary to create some lines to define the link field of
the relationship many-to-many. In oqc_X modules is used in the file
OpenQuotesandContracts.php on the path:
/sugarcrm/custom/Extension/modules/oqc_Contract/Ext/Vardefs/
On this file is necessary to specify the field of their relationship, by adding the following
lines. For example with the Project s module:
//Contracts and Project's relationship test
'project',
'type' => 'link',
'relationship' => 'oqc_Contract_project',
'source' => 'non-db',
);
?>
//Contracts and Project's relationship test
In the original modules of sugarCRM this file doesn't exists, so it is necessary to create a
file with same name: OpenQuotesandContracts.php on the path:
/sugarcrm/custom/Extension/modules/Project/Ext/Vardefs/ (if doesn't exist this path you
need to create it)
In the file it must be specified the link field of the relationship with the contracts. Example
With module projects:
//Relationship test
'oqc_contract',
'type' => 'link',
'relationship' => 'oqc_Contract_project',
'source' => 'non-db',
);
?>
//Relationship test
METADATA
In the metadata file must be defined the relationship between the modules, Fields of the
database are also defined in this file. There is a file for each relationship, since it is a Manyto-
Many relationship. You must creathe the file oqc_ _
MetaData.php on the path:
/sugarcrm/metadata/
It is recommended to copy a file that already exists in that model with similar relationship.
Example with Project's module:
file: /sugarcrm/metadata/oqc_Contract_projectMetaData.php:
( note that the project module is in lower case)
$dictionary["oqc_Contract_project"] = array (
'table' => 'oqc_contract_project',
'fields' =>
array (
0 =>
array (
'name' => 'id',
'type' => 'varchar',
'len' => 36,
),
1 =>
array (
'name' => 'date_modified',
'type' => 'datetime',
),
2 =>
array (
'name' => 'deleted',
'type' => 'bool',
'len' => '1',
'default' => '0',
'required' => true,
),
3 =>
array (
'name' => 'oqc_contract_ida',
'type' => 'varchar',
'len' => 36,
),
4 =>
array (
'name' => 'project_idb',
'type' => 'varchar',
'len' => 36,
),
),
'indices' =>
array (
0 =>
array (
'name' => 'oqc_contract_projectpk',
'type' => 'primary',
'fields' =>
array (
0 => 'id',
),
),
1 =>
array (
'name' => 'oqc_contract_project_ida1',
'type' => 'index',
'fields' =>
array (
0 => 'oqc_contract_ida',
),
),
2 =>
array (
'name' => 'oqc_contract_project_idb2',
'type' => 'index',
'fields' =>
array (
0 => 'project_idb',
),
),
3 =>
array (
'name' => 'oqc_contract_project_idc3',
'type' => 'index',
'fields' =>
array (
0 => 'oqc_contract_ida',
1 => 'project_idb',
),
),
),
'relationships' =>
array (
'oqc_Contract_project' =>
array (
'lhs_module' => 'oqc_Contract',
'lhs_table' => 'oqc_contract',
'lhs_key' => 'id',
'rhs_module' => 'Project',
'rhs_table' => 'project',
'rhs_key' => 'id',
'relationship_type' => 'many-to-many',
'join_table' => 'oqc_contract_project',
'join_key_lhs' => 'oqc_contract_ida',
'join_key_rhs' => 'project_idb',
),
),
);
?>
Table files
So that sugar can repair and build the table you must create a line to refer the metadata file.
On the files: OpenQuotesandContracts.php and tabledictionary.ext.php, respectively, on the
paths:
/sugarcrm/custom/Extension/application/Ext/TableDictionary/
/sugarcrm/custom/application/Ext/TableDictionary/
you must insert a line before ?>. Example with Project's module:
include('metadata/oqc_Contract_projectMetaData.php');
REBUILDING TABLES AND RELATIONSHIPS
After modifing and creating all these files is necessary to enter in sugarcrm on the browser,
go into admin> repair and repair relationships,quick repair and repair DB (database). When
repaired the database is repared sugar will create the table with the fields defined in your
metadata file.
Creating a Sub-panel
In order to create a subpanel on the oqc_something modules it must be created some
definitions on the file: OpenQuotesandContracts.php on the path:
/sugarcrm/custom/Extension/modules/oqc_Contract/Ext/Layoutdefs/
On this file must be created lines to define the sub-panel of the original sugarCRM module,
in my case, project. Example with Project's module.
//Teste subpainel de projetos em contratos
100,
'module' => 'Project',
'subpanel_name' => 'default',
'get_subpanel_data' => 'project',
'add_subpanel_data' => 'project_idb',
'title_key' => 'lbl_project', //this key must be translated on the en_us.lang file
);
?>
//teste subpainel de projetos em contratos
To set up the title of the sub-panel is necessary to put a line on the language file, in my case
was made with Portuguese pt_br.lang.php for English must be done to file en_us.lang.php
on the path:
/sugarcrm/modules/oqc_Contract/language/
This must be done on the language cache file( pt_br.lang.php) as well, on the path:
sugarcrm/cache/modules/oqc_Contract/language/pt_br.lang.php
The key on the previous step must be used: Example with lbl_project:
$mod_strings = array (
'lbl_project'=> 'Projetos',
than Repair extensions and Quick repair.
To set up a oqc Sub-panel on the Original Module (in my case Project), since the
relationship and table are already defined, you just need to define the sub-panel on the
original module on the path: (is it doesn't exists than create it, create the file as well)
sugarcrm/custom/Extension/modules/Project/Ext/Layoutdefs/OpenQuotesAndContracts.php
Example with projectsXoqc_contract:
note oqc_contract
in lower case
'order' => 100,
'module' => 'oqc_Contract',
'subpanel_name' => 'default',
'get_subpanel_data' => 'oqc_contract',
'add_subpanel_data' => 'oqc_Contract_ida',
'title_key' => 'LBL_OQC_CONTRACT_SUBPANEL_TITLE',
);
?>
Quick repair it, and it should be ready to use!

Comments

Popular posts from this blog

Dynamically generate Text Box and update its value in database

Hi Guys, This Post is in reference to the time I spent in order to write just a piece of code in PHP, though it would be very easy for most of the guys but if you are still learning then its a good thing to be proud of. Ok let me explain a little about what I was trying to do and how I did it. Requirement : I need to list down all the names of guys who falls under a certain category and display them on another page. I can do this by creating static text box in the landing page and fetch the value from the database OR I can dynamically generate the text box and display all the data there. For that first call the sql query of the condition like this. $sql = mysql_query("SELECT * FROM `list1` WHERE BLAH BLAH"); Now use the While query in order to get all the data required  <?php       while ($row = mysql_fetch_array($sql))       {           ?>       <tr>       <td  align="center" valign="middle" scope="row">

Jquery Carousels

Jquery Carousels we all love carousels they are a fantastic way to give the effects we want our visitors to have, more than that we have multiple components to show like images, links, text etc. There are lot many ways to achieve it, Jquery is ofcourse the best possible option available outside. We all search for lot of ems it can be Jquery Flexslider  or Jcarousel Lite  whatever you choose, customization is required, in this tutorial I am not going to focus on how to install these libraries rather one step ahead, to let you know how these carousels can be called multiple times in the same page having their controls working respectively for each carousel instance. So, lets get started with the HTML <div id="sideRight"> <div id="first">       <!-- Do not change the class and tag type, as this will remain as it is for all the following divisions-->       <p class="containheader">Plans for you <a href=&quo

IE 10 in IE7 compatibility mode returns error: 'SCRIPT3: Member not found'

Lately I upgraded my Internet Explorer to newer version which is 10, and was quite happy about it, but that doesn't seem to last long, when I tested my site changing the browser mode IE7, specifically using IE10, then jquery have thrown an error saying "member not found" , I was not surprised as such issues I have seen before as well, and was sure that there was JS code messed up from my side, after scanning through all the methods etc. I was not able to figure out anything, even was not sure what to search on Internet. After introspecting it was clear that this bug was not coming while I was using IE 7 from IE 9 browser installed, it came only after upgrading. At last, I found the root cause, it was not the jquery, not my JS code, not the custom dropdowns, even not all the pages were throwing this error, this was due to the jquery validate plugin, and thanks to  jester12345  who acknowledged the bug at  https://github.com/jzaefferer/jquery-validation/issues/845  an