In suiteCRM how does one get about changing the Address field country and state text fields to be dropdowns? - sugarcrm

I am developing a custom suite CRM module however I find the Address field limiting since it uses text fields for country and state fields.
I have tried researching it by following instructions on this site:
https://johndopenotes.wordpress.com/2013/01/08/sugarcrm-change-address-state-and-country-to-dropdown-menu/
However I am stuck at step 5 since my custom module does not have a metadata directory???
Go to /custom/modules/Leads/metadata and update editviewdefs.php. Look for this code:
array (
'name' => 'primary_address_street',
'hideLabel' => true,
'type' => 'Address',
'displayParams' =>
array (
'key' => 'primary',
'rows' => 2,
'cols' => 30,
'maxlength' => 150,
),
),
1 =>
array (
'name' => 'alt_address_street',
'hideLabel' => true,
'type' => 'Address',
'displayParams' =>
array (
'key' => 'alt',
'copy' => 'primary',
'rows' => 2,
'cols' => 30,
'maxlength' => 150,
),
),
and update the type from Address to CustomAddress
array (
'name' => 'primary_address_street',
'hideLabel' => true,
'type' => 'CustomAddress',
'displayParams' =>
array (
'key' => 'primary',
'rows' => 2,
'cols' => 30,
'maxlength' => 150,
),
),
1 =>
array (
'name' => 'alt_address_street',
'hideLabel' => true,
'type' => 'CustomAddress',
'displayParams' =>
array (
'key' => 'alt',
'copy' => 'primary',
'rows' => 2,
'cols' => 30,
'maxlength' => 150,
),
),
Can someone please give me a pointer as to how I can make address field in my custom module dropdowns instead of text fields?

Instead to choosing Address type field you can use combination of multiple fileds. For an example for street address you can use (datatype:textField)
Similarly for city you can add a text filed. Now for state and country you can use dropdown and add dropdown list as per your need
And for zipcode you can use integer / text field as per your requirement.
Now to make state dependend to country you can use custom javascript / jquery in following way
Add a reference to the javascript file you are going to add at the
end of custom/modules/<>/metadata/[edit|detail]viewdefs.php
$viewdefs['Opportunities']['EditView']['templateMeta']['includes'] = array ( array ( 'file' => 'path/to/file/filename.js', ), );
Add the javascript file you want to include into the location you
referenced above.
Quick Repair from the admin section, then browser refresh

It should just be a case of updating the vardefs for the field so the type is set to enum and the options point to your dropdown list. Then run a repair and rebuild.
The guide you've linked to looks like it is creating a new field type, which I think is overkill. It's also using Sugar logic to make the 2 lists dependent, but I'm not sure that's a feature in SuiteCRM.

Related

Typo3 - How to add dynamic value in TCA MM table

I'm trying to add a column to the relation table (MM table) in Typo3. Let's say I have my tables user, wanted_car and wanted_car_mm which is my relation table. So in wanted_car_mm I'll know what user want which car, but I want to add the column need_faster in wanted_car_mm, which is a boolean, that tells me who should have it faster. A lot of users could need it faster, there's no order.
How do I add this column, map the value and correctly retrieve this information when I get all my users?
I currently have this in my TCA config for user:
'wanted_cars' => array(
'exclude' => 1,
'label' => 'LLL:EXT:caa_my_plugin/Resources/Private/Language/locallang_db.xlf:my_title',
'l10n_mode' => 'exclude',
'config' => array(
'type' => 'select',
'foreign_table' => 'wanted_car',
'MM' => 'wanted_car_mm',
'MM_insert_fields' => array('need_faster' => '???'),
'MM_table_where' => ' AND wanted_car_mm.need_faster = ???',
'maxitems' => 9999,
'multiple' => 0,
'renderType' => 'selectCheckBox',
),
),
I feel like this is how I should add the column and retrieve it correctly, but I have no clue how to map the correct value.. that I should also put in my where clause.. I don't know how this can be possible going like this, but I can't find any other way of doing it.
The value must be specified when creating a user.
You need an intermediate table for that. The full docs for that can be found on https://docs.typo3.org/m/typo3/reference-tca/master/en-us/ColumnsConfig/Type/Inline.html
a screenshot and old example which still should work can also be found on https://wiki.typo3.org/Inline_Relational_Record_Editing_Attributes

Creating an Advanced Search field capable of searching multiple module fields

I am currently encountering issues trying to build a custom search field (itself bound to an unused field on a Module) to search two Phone Number fields. The documentation covering modifications of a search field are really poor, but I have the following in place in the module's SearchFields.php
'phone' =>
array (
'query_type' => 'default',
'operator' => '=',
'db_field' =>
array (
0 => 'home_phone_c',
1 => 'work_phone_c',
),
),
The field itself returns no results, so am I missing something that would prevent this from working?
why not you use "sub-query" operator for this? See SearchFields.php inside metadata folder of Account module. You will see entry like following:
'email' =>
array (
'query_type' => 'default',
'operator' => 'subquery',
'subquery' => 'SELECT eabr.bean_id FROM email_addr_bean_rel eabr JOIN email_addresses ea ON (ea.id = eabr.email_address_id) WHERE eabr.deleted=0 AND ea.email_address LIKE',
'db_field' =>
array (
0 => 'id',
),
'vname' => 'LBL_ANY_EMAIL',
),
this will help you to understand the sugar logic of doing it.
You need to designate the correct tables. Try the below code (or use the tables that you're searching):
'phone' =>
array (
'query_type' => 'default',
'operator' => '=',
'db_field' =>
array (
0 => 'accounts_cstm.home_phone_c',
1 => 'accounts_cstm.work_phone_c',
),
),

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"

wordpress WP Query and Custom Field filtering

I've encoutered problem with filtering pages to display in WP query.
I use Codex WP query reference for custom fields with ACF (Advanced Custom Fields plugin - but it doesn't matter, couse it works same as WP custom field) parameters to filter pages.
In "Multiple Custom Field Handling" paragraph, Codex got an example with 2 conditions. We can use OR or AND relation. I works for both until you have 3rd condition (array).
They use example:
'relation' => 'OR',
array(
'key' => 'color',
'value' => 'blue',
'compare' => 'NOT LIKE'
),
array(
'key' => 'price',
'value' => array( 20, 100 ),
'type' => 'numeric',
'compare' => 'BETWEEN'
)
It has only 2 arrays. When I put 3rd, nothing shows. In debug mode I can see an error:
WordPress database error: [Lost connection to MySQL server during query]
When I use AND it works, but I got to use OR. Unfortunately it makes MySQL disconnect.
I've tryed asking phpMySQL for same query WP does. It couses problem - phpMyAdmin says same:
Lost connection
Any Idea?
Maybe I should try different aproach for filtering? (maybe I should use taxonomy?)
Here is code I use:
$query_array = array('relation' => 'OR');
array_push($query_array,
array(
'key' => 'filter1',
'value' => 'value1',
'compare' => 'LIKE'
),
array(
'key' => 'filter1',
'value' => 'value2',
'compare' => 'LIKE'
),
array(
'key' => 'filter1',
'value' => 'value3',
'compare' => 'LIKE'
)
);
$args = array(
'order' => $order_array,
'meta_key' => $meta_key,
'orderby' => $orderby,
'post_type' => 'page',
'paged' => $paged,
'post__in' => $postIDs,
'posts_per_page' => 12,
'paged' => get_query_var('paged'),
'meta_query' => $query_array
);
query_posts($args);
?>
(variables for $args are set of course)
I don't know why I can't use
'compare' => '='
but probably it is why I can't use:
$query_array = array('relation' => 'OR');
array_push($query_array,
array(
'key' => 'filter1',
'value' => array('value1', 'value2', 'value3'),
'compare' => 'IN'
)
);
Just wanted to say that your comment helped me; I'd been butting my head against a very similar problem for a while. I'm using ACF too, and using it to attach items of one post type to another custom post type was easy - for instance, to Attach Person_1 and Person_3 to "Project_A".
This made it easy to list out which users were attached to specific projects. But when it came to do the same in reverse - to show which projects were attached to which users - it became a massive headache.
I finally figured it out, in part thanks to your comment - I'll post my solution here in case someone else comes along with the same problem:
$args = array(
'numberposts' => -1,
'post_type' => 'project',
'meta_query' => array(
'relation' => 'IN',
array(
'key' => 'people',
'value' => ';s:1:"' . $person->ID . '";',
'compare' => 'LIKE'
)
)
);
In short: because the ACF values in repeater fields et cetera are serialized, the compare keyword has to be "LIKE", and I added some context to the value to eliminate false returns - just searching for an ID like "1" would match a lot of the (wrong) posts, but the ";s1;" part ensures that the given value is at index 1, which in my case is the correct index.
So it would need tweaking from case to case. Inspecting what you're trying to match up with var_dumping "get_post_meta($post->ID, 'people')" is helpful for getting the value correct.

how to remove sorting from listView in specific column in SugarCRM

How do I remove sorting from listView (eg Account) in specific column in SugarCRM?
Specific : I want to Remove sorting on Name field (only one field) of ListView of Account Module.
Set 'sortable' => false for the field in the listviewdefs.php. Edit custom/modules/Accounts/metadata/listviewdefs.php and set such as:
'EMAIL1' =>
array (
'width' => '16%',
'label' => 'LBL_LIST_EMAIL_ADDRESS',
'sortable' => false,
'customCode' => '{$EMAIL1_LINK}{$EMAIL1}</a>',
'default' => true,
),