Populating a field when choosing a relate field _ suite crm - sugarcrm

i'm using suite crm 7.7.5
when i create an opportunity and i choose an account from a relate field, i want a field (country) to be auto populated with the value of the country of the account chosen.
for this, i tried to add the code
$dictionary['Opportunity']['fields']['country_c']['populate_list']= array('id','name','country_c');
$dictionary['Opportunity']['fields']['country_c']['field_list'] = array('account_id_c','account_name','country_c');
in the file \custom\Extension\modules\Opportunities\Ext\Vardefs\sugarfield_country_c.php
knowing that country_c is the name of the column country in the table accounts and the second country_c is the id of the field country in the layout opportunity
but that doesn't work, could someone help me to figure out the reason?
PS : i've tried to follow this tutorial https://developer.sugarcrm.com/2011/08/31/howto-using-a-relate-field-to-populate-a-custom-field/

Here is the extension on #Bozic solution.
If someone is trying to autopopulate related fields based on selection then here is the solution. (Those who are facing "No match for field: Account Name")
Scenario: I have Account Owner (relate to User module) field in Accounts module. And in Cases module I am fetching Account owner fields based on Account selection.
In /custom/modules/Cases/metadata/editviewdefs.php
0 => array(
'name'=>'account_name',
'displayParams' => array (
'field_to_name_array' => array(
'id'=>'account_name',
'assigned_user_name' => 'account_owner_case_c',
'assigned_user_id' => 'user_id2_c',
),
),
),
Note:
assigned_user_name is field id of Account owner from Accounts module
assigned_user_id is id field of Account owner
account_owner_case_cis field of Case Account Owner from Case module
account_name is selection field from case module (on selection of this field account owner will get populate)

You should go to custom/modules/{YOUR MODULE}/metadata/editviewdefs.php and edit editviewdefs.php file.First you need to find array in which your relate field(account_name) is defined. It will look similar to this, maybe with some more parameters.
array (
'name' => 'account_name',
),
Now you need to map data from relate field(country_c) to new field(lets say populated_country_c). After editing your array will look something like this.
array (
'name' => 'account_name',
'displayParams' => array (
'field_to_name_array' => array(
'id'=>'account_id_c',
'name'=>'account_name',
'country_c' => 'populated_country_c',
),
),
),
Now populated_country_c is the new field in which the data about country will be populated when you choose account in the relate field. So we also need to create that new field. You can do it through studio or manually just by adding new array. Finally your file will look like this
array (
'name' => 'account_name',
'displayParams' => array (
'field_to_name_array' => array(
'id'=>'account_id_c',
'name'=>'account_name',
'country_c' => 'populated_country_c',
),
),
),
array (
'name' => 'populated_country_c',
'label'=> 'LBL_POPULATED_COUNTRY'
),
Now when choosing new account from relate field, populated_country_c will be populated with country_c field from selected account.

Use field billing_account_country rather than country_c, and also use account_id with account_name. The name and the id have to coincide to the same table, I believe.

Related

How to change the default order of the sub panels in the opportunities module

I have a need to change the default order of the sub panels in the opportunities module. I have been looking for a solution for a while and have not found a solution that works.
I am using SugarCRM CE 6.5.13
Thanks in advance.
Your question is actually unclear. Are you asking for the order of a subpanel meaning how to place one subpanel above another. Or is your question concerning the order of the data inside a subpanel?
A fast response to both is:
in {MainModule}/metadata/subpaneldefs.php there should be the sort order declared for the subpanel like this:
$layout_defs[{MainModule}] = array(
// list of what Subpanels to show in the DetailView
'subpanel_setup' => array(
'{TheSubpanel}' => array(
'order' => 1, // influences the place of the subpanel relative to the other subpanels
'module' => '{TheSubpanel}',
'subpanel_name' => 'default', // attention please check the subpanel module to make sure there is not another setting overriding this setting
'sort_order' => 'desc',
'sort_by' => 'date_entered',
...
check also the file defined above that contains the subpanels fields. In this case it can be found in {TheSubpanel}/metadata/subpanels/default.php
$module_name = '{TheSubpanel}';
$subpanel_layout = array(
'top_buttons' => array(
'where' => '',
'sort_order' => 'desc',
'sort_by' => 'date_entered',
Please consider that after a change you need to run 'rebuild & repair' and if you manually clicked on a sort field then you should clear your cookie cache and log in again too.
There are other questions on stack overflow concering this like how-to-change-default-sort-in-custom-subpanel-sugarcrm
If you do not want code level customization then you can just drag and drop the sequence of subpanels on detail view of record. The sequence of subpanel will be saved.

get_entry_list() method with query parameter on sugar crm 7 does not work

My code is as below..
Please note that I am trying to retrive all the accounts whose where the Accounts.name='bhagya'.
The same query workes for me in SugarCRM Version 6.5 (Community edition) but in case of SugarCRM 7 it is not working when I mention query parameter. If I mention 'query'=>'' then I get all the records from the sugarcrm 7 server. It fails when I specify any filter for query parameter. I am using RestAPI - 4.1
$get_entry_list_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => 'Accounts',
//The SQL WHERE clause without the word "where".
//'query' => "Accounts.billing_address_postalcode='60329'",
// 'query' => "Accounts.name='Ingrid Rofalsky'",
'query'=>'',
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => "",
//The record offset from which to start.
'offset' => 0,
//A list of fields to include in the results.
'select_fields' => array(
'id',
'name',
),
//A list of link names and the fields to be returned for each link name.
'link_name_to_fields_array' => array(),
//The maximum number of results to return.
'max_results' => 10,
//If deleted records should be included in results.
'deleted' => 0,
//If only records marked as favorites should be returned.
'favorites' => false,
);
print_r($get_entry_list_parameters);
$get_entry_list_result = call('get_entry_list', $get_entry_list_parameters, $url);
echo '<pre>';
print_r($get_entry_list_result);
echo '</pre>';
Can some one help me on this..
Thank you.
Regards
- Bhagya
The Rest API has changed a lot in Sugar7.
The URL for the invokation should look like
http://servname.com/pro720/rest/v10/Accounts?filter[0][name][$starts]=B&filter[0][email_addresses.email_address]=burgers#example.com&fields=name,account_type,description,email
Where you are filtering the accounts with a name that starts with B, the mail address is burgers#example.com and where you retrieve only the fields name,account_type,description and email
Changing the module name to lowercase in query option solved this problem.
I got the answer for my query from below link.
https://community.sugarcrm.com/sugarcrm/topics/get_entry_list_method_with_query_parameter_on_sugar_crm_7_does_not_work?topic-reply-list%5Bsettings%5D%5Bfilter_by%5D=all&topic-reply-list%5Bsettings%5D%5Bpage%5D=1#reply_14588280
Thanks again
Regards
- Bhagya

Get list of all documents related to an account

I'm working on an app to download all notes and documents related to an account in Sugar CRM. I'm building it as a C# console application, using the web service API as a web reference in my solution.
I think I have figured out the notes part but I can't figure out the documents part. Can anyone show me how to get a list of all documents per account using the web service API calls?
I am assuming that I should use get_relationships() to get documents, but how do I get the accounts module id? I don't have access to the database.
(My client is using sugar crm version 6.7.1 corporate)
Okay, that you should use the API get_relationships. See the example to follow.
<?php
$get_relationships_parameters = array(
'session'=>$session_id,
//The name of the module from which to retrieve records.
'module_name' => 'Accounts',
//The ID of the specified module bean.
'module_id' => '13111fcd-1884-2a71-0b37-50b7d0f188f6',
//The relationship name of the linked field from which to return records.
'link_field_name' => 'documents',
//The portion of the WHERE clause from the SQL statement used to find the related items.
'related_module_query' => '',
//The related fields to be returned.
'related_fields' => array(
'id',
'name',
),
//For every related bean returned, specify link field names to field information.
'related_module_link_name_to_fields_array' => array(
),
//To exclude deleted records
'deleted'=> '0',
//order by
'order_by' => '',
//offset
'offset' => 0,
//limit
'limit' => 5,
);
$get_relationships_result = call("get_relationships", $get_relationships_parameters, $url);
?>
and you see result:
stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 8b4c0450-1922-498f-4601-52272fa6e494
[module_name] => Documents
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 8b4c0450-1922-498f-4601-52272fa6e494
)
[name] => stdClass Object
(
[name] => name
[value] => WebProxyService_A.png
)
)
)
)
[relationship_list] => Array
(
)
)
at url https://gist.github.com/amusarra/6436845 you will find the complete example. To get the account Id should use the API or get_entry get_entries.
I hope I have been of help.
Antonio

SugarCRM filter search result by custom field from current user account

I have the custom field "country_id_c" in both "User" and "CustomModule", I need to limit the user to see only lines from his region (filtering it by country_id_c).
There are two search forms:
when you see the search result of CustomModule from menu
when you add CustomModule as a relationship to other module by using
picker (pop up window).
I found how to filter the result in 1 case with hard-coded value:
file: custom/modules/CustomModule/metadata/SearchFields.php
$searchFields['CustomModule'] = array (
...
'country_id_c' =>
array (
'query_type' => 'format',
'operator' => '=',
'value' => 'Argentina',
'db_field'=>array('country_id_c',)
),
...
what I'm missing here is how to get the current logged-in user's country_id_c. And how to do the same for the (2) search form.
You can access the value by adding:
globals $current_user;
$current_user->country_id_c

Yii fail to retrieve max column value

I have two models, one is Auction, the other is Bid.
An Auction has many Bids. they are associated by foreign key auction_id in Bid
Now, I want to find the max value of the Bid's price for each Auction.
$dataProvider = new CActiveDataProvider('Auction', array('criteria' => array(
'with' => array(
'bids' => array(
'alias'=>'b',
'group' => 'auction_id',
'select' => 'max(b.price) as maxprice'
)
)
)
)
);
And I have defined a maxprice property in Auction's model class.
However, if I try to retrieve the maxprice property, it returns NULL.
To be more specific, I render the $dataprovider to a view page, it fails to get the maxprice property.
PS:
I executed the query in mysql, the query result turns out to be correct.
So, there must be something wrong with the Yii code
SQL code:
SELECT `t`.`id` , max(b.price) as maxprice
FROM `auction` `t`
LEFT OUTER JOIN `bid` `b` ON (`b`.`auction_id`=`t`.`id`) GROUP BY auction_id
Put the value you want before the relation, like so:
$dataProvider = new CActiveDataProvider('Auction', array('criteria' => array(
'select' => 't.*, max(b.price) as maxprice',
'with' => array(
'bids' => array(
'alias'=>'b',
'group' => 'auction_id',
'together'=>true,
)
You can replace the "t.*" with specific field names if you like.
OR you can simply use the select, join and group attributes on your Auction model and skip the relation altogether.