AnsweredAssumed Answered

DropDownHelper class not working as documented

Question asked by Roman Nique on May 9, 2017
Latest reply on May 10, 2017 by Francesca Shiekh


I was following documentation for Managing Lists in Sugar 7.8 (7.7 is the same):… 


Then I saw the source code and compared to source code from 6.5 and there are a lot of undocumented changes (mostly missing things). The recommendation from those official docs to use dropdowns for saving new lists is:

require_once ('modules/Studio/DropDowns/DropDownHelper.php');
$ddh_obj = new DropDownHelper();

$params = array();

$params['dropdown_name'] = 'my_changing_list';

here goes code to iterate through some list to set each item of the list into the $params array.
One special option is to set $params['use_push'] = true/false, in order to update/add values while keeping old values.


Issues with the DropDownHelper class:

  • The saveDropDown() function in DropDownHelper.php is declared as static, so no need to instantiate, just use DropDownHelper::saveDropDown($params).
  • The 'use_push' parameter is not used in DropDownHelper.php, neither passed to save_custom_dropdown_strings() (implemented in Common.php), so the documentation is wrong about its purpose.
  • In DropDownHelper.php from Sugar 6.5 there was an extra parameter to set the language: $params['dropdown_lang'] In 7.7 and 7.8, some of the code is still there, but not passed anymore to save_custom_dropdown_strings() 
  • The save_custom_dropdown_strings() in Common.php doesnt work well neither, because it doesn't allow to add new items to the list doesn't discriminate if we want to update or replace the list, check lines 260-264, specially the conditiional at line 264:
 //iterate and overwrite/create the dropdown entries
foreach ($new_dd_strings as $list_key => $list_val) {
//process new string values if they exist in $app_list_strings and the new entry is different.. OR
//if the key doesn't exist in $app_list_strings but there is a new value in the passed in strings
//ignore if values are same or there is a new blank value
if (isset($app_list_strings[$list_key]) && $app_list_strings[$list_key] != $new_dd_strings[$list_key]) {

$new_dd_strings is the list we want to save, so if $list_key is not set in $app_list_strings[], it won't allow to add new item, despite the comments above that line state the opposite.

UPD: what it doesn't allow is to update instead of replacing.


Our current solution is avoid using that object and save lsits directly, however I point this out because it cost us some time to realize that the problem wasn't our code but these modifications to the working 6.5 class.