How to replace a build in relationship field by a flexrelate field - sugarcrm

For example in Opportunities and Cases there are relationship fields directly pointing to accounts. I have a custom module that integrates into those modules. I could add a separate relate field for the custom module, but what I want is a flexrelate allowing only Accounts and the Custom module. This works fine by setting a special options list in the parent_name. but results in a parent_type and parent_id field in db.
How do I configure the flexrelate so that on selecting accounts as parent_type it save to account_id and on selecting the custom module it saves to it's id field?
The options for the flexrelate:
$app_list_strings['parent_type_display_custom']['CustomMod'] = 'CustomMod';
$app_list_strings['parent_type_display_custom']['Accounts'] = 'Accounts';
$app_list_strings['record_type_display_custom']['CustomMod'] = 'CustomMod';
$app_list_strings['record_type_display_custom']['Accounts'] = 'Accounts';
The additional vardefs for Cases:
$dictionary["Case"]["fields"]["parent_type"] = array (
'name' => 'parent_type',
'type' => 'link',
'vname' => 'LBL_PARENT_TYPE',
'type' => 'parent_type',
'dbType' => 'varchar',
'group' => 'parent_name',
'options' => 'parent_type_display_custom',
'len' => '255',
);
$dictionary["Case"]["fields"]['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(_custom)',
'source' => 'non-db',
'options' => 'record_type_display_custom',
);
$dictionary["Case"]["fields"]['parent_id'] =
array(
'name' => 'parent_id',
'vname' => 'LBL_PARENT_ID',
'type' => 'id',
'required' => false,
'reportable' => true,
'comment' => 'eighter the Id of an account or a custommodule'
);

Does this SugarCRM developer blog post help?
http://developers.sugarcrm.com/wordpress/2011/05/16/howto-create-a-flex-relate-for-other-modules/

Related

In SuiteCRM how to add custom field in sub panel from relationship table?

I have a module and a sub panel with another module in relationship with it.
As shown in below image-
In the above image its a sub-panel of a module in the relationship,
I have added a column in the relationship table in database.
My requirement is to add that field in this sub-panel list view like shown in image in red rectangle, which is ideally not possible from the studio as per my knowledge.
If anyone has idea to do stuff like this please share.
There may come a time in the development of a custom SuiteCRM module when it would be handy to store additional data in the relationship table between two modules. This is not possible in studio or module builder and is not that straight forward even for an experienced coder unless you have a deep understanding of SuiteCRM underlying architecture.
Step 1 The first thing you need to do is define your new fields in the metadata for the relationship. I will be adding the field in the relationship between a custom module FP_events and Contacts. The relationship fp_events_contacts is a many to many and the subpanel will be displaying the field in the contacts subpanel on the FP_events module.
This file can be found at custom/metadata/fp_events_contactsMetaData.php
In the code below notice that I added a field called date_cancelled with type date to the fields array.
$dictionary["fp_events_contacts"] = array (
'true_relationship_type' => 'many-to-many',
'relationships' =>
array (
'fp_events_contacts' =>
array (
'lhs_module' => 'FP_events',
'lhs_table' => 'fp_events',
'lhs_key' => 'id',
'rhs_module' => 'Contacts',
'rhs_table' => 'contacts',
'rhs_key' => 'id',
'relationship_type' => 'many-to-many',
'join_table' => 'fp_events_contacts_c',
'join_key_lhs' => 'fp_events_contactsfp_events_ida',
'join_key_rhs' => 'fp_events_contactscontacts_idb',
),
),
'table' => 'fp_events_contacts_c',
'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' => 'fp_events_contactsfp_events_ida',
'type' => 'varchar',
'len' => 36,
),
4 =>
array (
'name' => 'fp_events_contactscontacts_idb',
'type' => 'varchar',
'len' => 36,
),
5 =>
array (
'name' => 'invite_status',
'type' => 'varchar',
'len'=>'25',
'default'=>'Not Invited',
),
6 =>
array (
'name' => 'accept_status',
'type' => 'varchar',
'len'=>'25',
'default'=>'No Response',
),
7 =>
array (
'name' => 'email_responded',
'type' => 'int',
'len' => '2',
'default' => '0',
),
8 =>
array (
'name' => 'date_cancelled',
'type' => 'date',
),
),
'indices' =>
array (
0 =>
array (
'name' => 'fp_events_contactsspk',
'type' => 'primary',
'fields' =>
array (
0 => 'id',
),
),
1 =>
array (
'name' => 'fp_events_contacts_alt',
'type' => 'alternate_key',
'fields' =>
array (
0 => 'fp_events_contactsfp_events_ida',
1 => 'fp_events_contactscontacts_idb',
),
),
),
);
Once you have added your desired fields to the fields arrays do a quick repair and rebuild from the admin panel of SuiteCRM and then execute the suggested SQL queries this will add the fields to the database table for the relationship. (I double-checked that the fields were added by going into phpmyadmin and looking at the fp_events_contacts_c table.)
Step 2 Your fields are now defined and in the actual database table but your only halfway their if you want your fields to actually be displayed in the subpanel. The next thing you want to do is define your new fields in the vardefs for the relationship. This is done by adding a file in the custom/Extensions folder like so: custom/Extension/modules/Contacts/Ext/Vardefs/CAN_BE_ANY_NAME.php
In this file add the following three definitions for each field your adding. Pay careful attention that all the field names and ids match up between definitions as minor typos here will prevent the fields from showing in the subpanel and can be major pain to spot:
$dictionary['Contact']['fields']['e_date_cancelled'] =
array (
'name' => 'e_date_cancelled',
'rname' => 'id',
'relationship_fields'=>array('id' => 'cancelled_id', 'date_cancelled' => 'event_cancelled'),
'vname' => 'LBL_CONT_ACCEPT_CANCELLED',
'type' => 'relate',
'link' => 'fp_events_contacts',
'link_type' => 'relationship_info',
'join_link_name' => 'fp_events_contacts',
'source' => 'non-db',
'importable' => 'false',
'duplicate_merge'=> 'disabled',
'studio' => false,
);
$dictionary['Contact']['fields']['event_cancelled'] =
array(
'massupdate' => false,
'name' => 'event_cancelled',
'type' => 'date',
'studio' => 'false',
'source' => 'non-db',
'vname' => 'LBL_LIST_ACCEPT_CANCELLED',
'importable' => 'false',
);
$dictionary['Contact']['fields']['cancelled_id'] =
array(
'name' => 'cancelled_id',
'type' => 'varchar',
'source' => 'non-db',
'vname' => 'LBL_LIST_ACCEPT_CANCELLED',
'studio' => array('listview' => false),
);
Step 3 The final thing you need to do is define the fields in the actual layout defs of the subpanel. In this case, that file is located: custom/modules/Contacts/metadata/subpanels/FP_events_subpanel_fp_events_contacts.php
In the code below notice that I add my field event_cancelled (as defined in the step 2 vardefs) to list_fields array and further down in the array I also add e_date_cancelled and cancelled_id and mark their usage as query_only.
$subpanel_layout['list_fields'] = array (
'name' =>
array (
'name' => 'name',
'vname' => 'LBL_LIST_NAME',
'sort_by' => 'last_name',
'sort_order' => 'asc',
'widget_class' => 'SubPanelDetailViewLink',
'module' => 'Contacts',
'width' => '23%',
'default' => true,
),
'account_name' =>
array (
'name' => 'account_name',
'module' => 'Accounts',
'target_record_key' => 'account_id',
'target_module' => 'Accounts',
'widget_class' => 'SubPanelDetailViewLink',
'vname' => 'LBL_LIST_ACCOUNT_NAME',
'width' => '22%',
'sortable' => false,
'default' => true,
),
'phone_work' =>
array (
'name' => 'phone_work',
'vname' => 'LBL_LIST_PHONE',
'width' => '15%',
'default' => true,
),
'email1' =>
array (
'name' => 'email1',
'vname' => 'LBL_LIST_EMAIL',
'widget_class' => 'SubPanelEmailLink',
'width' => '20%',
'sortable' => false,
'default' => true,
),
'event_status_name' =>
array (
'vname' => 'LBL_STATUS',
'width' => '10%',
'sortable' => false,
'default' => true,
),
'event_accept_status' =>
array (
'width' => '10%',
'sortable' => false,
'default' => true,
'vname' => 'LBL_ACCEPT_STATUS',
),
'event_cancelled' =>
array (
'width' => '10%',
'sortable' => false,
'default' => true,
'vname' => 'LBL_ACCEPT_CANCELLED',
),
'edit_button' =>
array (
'vname' => 'LBL_EDIT_BUTTON',
'widget_class' => 'SubPanelEditButton',
'module' => 'Contacts',
'width' => '5%',
'default' => true,
),
'remove_button' =>
array (
'vname' => 'LBL_REMOVE',
'widget_class' => 'SubPanelRemoveButton',
'module' => 'Contacts',
'width' => '5%',
'default' => true,
),
'e_accept_status_fields' =>
array (
'usage' => 'query_only',
),
'event_status_id' =>
array (
'usage' => 'query_only',
),
'e_invite_status_fields' =>
array (
'usage' => 'query_only',
),
'event_invite_id' =>
array (
'usage' => 'query_only',
),
'e_date_cancelled' =>
array (
'usage' => 'query_only',
),
'cancelled_id' =>
array (
'usage' => 'query_only',
),
'first_name' =>
array (
'name' => 'first_name',
'usage' => 'query_only',
),
'last_name' =>
array (
'name' => 'last_name',
'usage' => 'query_only',
),
'salutation' =>
array (
'name' => 'salutation',
'usage' => 'query_only',
),
'account_id' =>
array (
'usage' => 'query_only',
),
);
Also, remember to add the label in this case LBL_ACCEPT_CANCELLED to the custom language strings.
I added it to: custom/Extension/application/Ext/Language/en_us.Advanced OpenEvents.php
$app_strings['LBL_ACCEPT_CANCELLED'] = 'Date Cancelled';
But it may work if added to the mod strings.
Now do another quick repair and rebuild from the admin panel and your custom relationship fields should now be showing up on the subpanel. You will now be able to add data into these fields in your module controller either via queries or through SuiteCRM bean framework.
Note you might have to manually go into the database and add some dummy data into those fields to confirm they are showing (Assuming you have not yet added any data to your new fields).
Cheers!

How can I create custom file upload field in opportunities

I'm working with sugar 8.3. I'm trying to create custom field for upload documents.
I have create vardef file, but when I click on save record, file uploaded properly but not display in record.
custom/Extension/modules/Opportunities/Ext/Vardefs/custom_upload.php
<?php
$GLOBALS['dictionary']['Opportunity']['fields']['filename'] = array (
'name' => 'filename',
'vname' => 'LBL_FILENAME',
'type' => 'file',
'dbType' => 'varchar',
'len' => '255',
'reportable' => true,
'comment' => 'File name associated with the note (attachment)',
'importable' => false,
'source' => 'non-db',
'docUrl' => 'doc_url',
);
$GLOBALS['dictionary']['Opportunity']['fields']['file_mime_type'] = array(
'name' => 'file_mime_type',
'vname' => 'LBL_FILE_MIME_TYPE',
'type' => 'varchar',
'len' => '100',
'comment' => 'Attachment MIME type',
'importable' => false,
'source' => 'non-db',
);
$GLOBALS['dictionary']['Opportunity']['fields']['file_url'] = array (
'name'=>'file_url',
'vname' => 'LBL_FILE_URL',
'type'=>'varchar',
'source'=>'non-db',
'reportable'=>false,
'comment' => 'Path to file (can be URL)',
'importable' => false,
);
Before save attachment screenshot
After save attachment screenshot
The whole scenario is not very clear from the code you have provided, i think that you should remove 'source'=>'non-db', attribute from these fields so that they get saved in database.
Don't forget to perform Repair and execute queries that gets generated in result of repair so that Sugar create appropriate fields in opportunities table for saving you uploaded file data.

how can I add a dependant custom field through the manifest.php

I am currently adding a web hook and want to add some fields programmatically through the manifest.php.
I have found the relevent information to add fields as below:
'custom_fields' => array (
array (
'name' => 'text_c',
'label' => 'LBL_TEXT_C',
'type' => 'varchar',
'max_size' => 255,
'require_option' => 'optional',
'default_value' => '',
'ext1' => '',
'ext2' => '',
'ext3' => '',
'audited' => 1,
'module' => 'Accounts'
)
);
the issue is that I cant seem to find how to make the fields dependant i.e. they will only be visible if another field contains a specific value.
any help would be greatly appreciated
In the definition array you would need to add the dependency attribute like so :
'custom_fields' => array (
array (
'name' => 'text_c',
'label' => 'LBL_TEXT_C',
'type' => 'varchar',
'max_size' => 255,
'require_option' => 'optional',
'default_value' => '',
'ext1' => '',
'ext2' => '',
'ext3' => '',
'audited' => 1,
'module' => 'Accounts'
'dependency' => 'equal($other_field,"other field value")'
)
);
This would replicate setting the dependency option in Studio.
The dependency formula
'equal($other_field,"other field value")'
Means show this field when the another field other_field equals the string "other field value"

Prestashop Module : Add multi select dropdown

I'm working on a module and I would like to know how to add multiple dropdown with fields_options.
$this->fields_options = array(
'Test' => array(
'title' => $this->l('Test'),
'icon' => 'delivery',
'fields' => array(
'IXY_GALLERY_CREATION_OCCASION' => array(
'title' => $this->l('DropdownList'),
'type' => 'select',
'multiple' => true , // not working
'identifier' => 'value',
'list' => array(
1 => array('value' => 1, 'name' => $this->l('Test 1 ')),
2 => array('value' => 2, 'name' => $this->l('Test 2)'))
)
),
),
'description' =>'',
'submit' => array('title' => $this->l('Save'))
)
);
This is how I'm doin if you're meaning that :
$combo = $this->getAddFieldsValues();
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Title'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'select',
'lang' => true,
'label' => $this->l('Nom'),
'name' => 'nom_matiere',
'options' => array(
'query' => $combo[0],
'id' => 'id_option',
'name' => 'name'
)
),
array(
'type' => 'select',
'lang' => true,
'label' => $this->l('Nom'),
'name' => 'name',
'options' => array(
'query' => $combo[1],
'id' => 'id_option',
'name' => 'name'
)
),
),
),
'submit' => array(
'title' => $this->l('Save'),
'name' => $this->l('updateData'),
)
),
);
the answer are not correctly .. due its not only dfined the field in the database, also must capture and stored in special way the values, in this example i demostrate to store as "1,2,3,6,8" using a single field
THE COMPLETE CODE AND ALL THE STEPS ARE AT: https://groups.google.com/forum/m/?hl=es#!topic/venenuxsarisari/z8vfPsvFFjk
here i put only the most important parts..
as mentioned int he previous link, added a new fiel in the model definition, class and the table sql
this method permits to stored in the db as "1,2,3" so you can use only a single field to relation that multiple selected values, a better could be using groupbox but its quite difficult, take a look to the AdminCustomers controller class in the controllers directory of the prestachop, this has a multiselect group that used a relational table event stored in single field
then in the helper form list array of inputs define a select as:
at the begining dont foget to added that line:
// aqui el truco de guardar el multiselect como una secuencia separada por comas, mejor es serializada pero bueh
$this->fields_value['id_employee[]'] = explode(',',$obj->id_employee);
this $obj are the representation of the loaded previous stored value when go to edit ... from that object, get the stored value of the field of your multiselect, stored as "1,3,4,6"
and the in the field form helper list of inputs define the select multiple as:
array(
'type' => 'select',
'label' => $this->l('Select and employee'),
'name' => 'id_employee_tech',
'required' => false,
'col' => '6',
'default_value' => (int)Tools::getValue('id_employee_tech'),
'options' => array(
'query' => Employee::getEmployees(true), // el true es que solo los que estan activos
'id' => 'id_employee',
'name' => 'firstname',
'default' => array(
'value' => '',
'label' => $this->l('ninguno')
)
)
),
an then override the post process too
public function postProcess()
{
if (Tools::isSubmit('submitTallerOrden'))
{
$_POST['id_employee'] = implode(',', Tools::getValue('id_employee'));
}
parent::postProcess();
}
this make stored in the db as "1,2,3"

zendframework 2 form populating checkbox values from a database

I am using zendframework 2 and doctrine 2. I want to populate the values of my checkboxes from values in my database (dependence injection).
I got the technique from: https://github.com/doctrine/DoctrineModule/blob/master/docs/form-element.md
This is my element (it works for select elements but not for checkboxes):
$this->add(array(
'type' => 'Zend\Form\Element\MultiCheckbox',
'name' => 'timesId',
'options' => array(
'label' => 'Please Select Your Availablity',
'value_options' => array(
'object_manager' => $this->getObjectManager(),
'target_class' => 'FormDependencies\Entity\AvailablityTimeTableList',
'property' => 'job',
),
),
'attributes' => array(
'value' => '1' //set checked to '1'
)
));
public function getObjectManager()
{
return $this->objectManager;
}
I cannot find the native doctrine 2 method for checkboxes.
The error message:
Fatal error: Cannot use object of type Doctrine\ORM\EntityManager as array
i have resolved it;
under type i needed to specify that its a :
'type' => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',
the complete code:
$this->add(array(
'type' => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',
'name' => 'timesId',
'options' => array(
'label' => 'Please Select Your Availablity',
'object_manager' => $this->getObjectManager(),
'target_class' => 'FormDependencies\Entity\AvailablityTimeTableList',
'property' => 'times',
'empty_option' => '--- please choose ---'
),