Editing of dropdown values via code

Hi!

I have the question: can I insert and edit dropdown values via code? I have a sheduler task and I want to edit dropdown in this sheduler. I see that I can try to rewrite custom/include/language/en_us.lang.php file but it doesn't seem to be clear and right solution.

Thanks for a response.
Parents
  • I have found solution. Thanks a lot to this source: https://phpbugs.wordpress.com/2012/01/27/sugarcrm-dynamically-create-dropdown-values/

    Here is my function for adding values to dropdown.

    /*  $dropdown_list - the name of list,
         $item_list - the array of new items (pairs key-value)
         $app_list_strings - array of dropdowns in SugarCRM (global variable)
     */
    function addItemsToDropdown($dropdown_list,$item_list,$app_list_strings) {
            require_once('modules/ModuleBuilder/MB/ModuleBuilder.php');
            require_once('modules/ModuleBuilder/parsers/parser.dropdown.php');
            $parser = new ParserDropDown();
            $params = array();
            $_REQUEST['view_package'] = 'studio'; //need this in parser.dropdown.php
            $params['view_package'] = 'studio';
            $params['dropdown_name'] = $dropdown_list; //replace with the dropdown name
            $params['dropdown_lang'] = 'en_us';//create your list...substitute with db query as needed
            foreach (array_merge($app_list_strings[$dropdown_list],$item_list) as $k=>$v) { //merge new and old values
                $drop_list[] = array($k,$v);
            }
            $json = getJSONobj();
            $params['list_value'] = $json->encode($drop_list);
            $parser->saveDropDown($params);
     }

    Hope it will help another people not to waste their time. )
    Good luck.
  • Hello Kramov,

    Can you please tell me In which file need to write this code?

Reply Children
No Data