Jorge Pereira

Api Filter with link fields not working

Discussion created by Jorge Pereira on Jun 28, 2016
Latest reply on Jun 23, 2017 by Brad Foster



I'm using the 7.7.0 Enterprise version, and following the example in this page (… ) to retrieve a list of beans with related information using a link field I found an issue that the fields to return using the link field were not sent in the output.


In the example we are listing the accounts and output some more information regarding the opportunities.


See SugarApi::formatBeans (SugarApi.php), Sugar will split the arguments by ',' instead of using the getFieldsFromArgs used in the SugarApi::formatBean function.


I would recomment replace in the SugarApi::formatBeans the following code:

if (!empty($args['fields']) && !is_array($args['fields'])) {     
    $args['fields'] = explode(',',$args['fields']);


if (!empty($args['fields']) && !is_array($args['fields'])) {     
    $args['fields'] = $this->getFieldsFromArgs($api, $args, null, 'view', $options['display_params']);

Or remove the code, and let the SugarApi::formatBean handle the $args['fields'] manipulation.



In case we also use the parameter view, there is also an issue in the MetaDataManager::getModuleViewFields function.


The $displayParams is passed as a reference to the function, and the first thing that happens is that the $displayParams gets a reset, so the 'opportunities' in the array is erased.


Please remove the line:

$displayParams = array();

In order to output the requested fields.


Hope this helps and improves Sugar products.


Best regards,

Jorge Sá