How can I get value in config_override.php via js

Hi all,

I would like to get parameters in config_override.php pass into .hbs via js controller

I try with this code below but doesn't work.

var custom = app.lang.getAppListStrings('custom_value');
this.testData = custom;

then return:

[object Object]

How to do this ?

Sugarcrm 7.6

Thanks,

M

  • I don't think this is possible out of the box (although I have a workaround below) for security reasons. The values in config/config_override include stuff like database connection details, which you might not even want your highest privileged application users (i.e. Administrators) to know. The way I'd implement this is by creating a custom endpoint:

    http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.6/API/Web_Services/Extending_Web_Servi…

    The main change I'd make to the endpoint api in the example is:

     public function MyGetMethod($api, $args){
      global $sugarconfig;
      return $sugarconfig['custom_value'];
      }
    

    You could then get the value using the loadData function in your controller like this:

    loadData: function () {
            var _this = this;
            App.api.call('GET', App.api.buildURL('name_of_your_endpoint', null, null, ''), null, {
                success: function (custom_value) {
                    _this.custom_value = custom_value;
                    _this.render();
                }}
            );
        },
    

    Let me know if you have any trouble with this method.

  • Hi Autchara Chaiprom,

    You can also use in the config_override.php the following:

    $sugar_config['additional_js_config']['custom_parameter'] = 'custom_value';
    

    After, you will be able to access the 'custom_parameter' with the following js code:

    App.config.custom_parameter
    

    When you initialize the js class you can also use:

    initialize: function(options) {
            this._super('initialize', [options]);
            this.custom_value = App.config.custom_value;
    }
    

    Hope this helps too.

  • Autchara Chaiprom This is a much better solution than my own, mark this as the correct solution.

    There may be times when you want to get the config.php values or you can't change config_override, but 95% go for Jorge's solution.    

  • Thank you both very much. Its work.

    in config_override.php

    $sugar_config['additional_js_config']['custom_parameter'] = 'custom_value';
    

    In js controller

    initialize: function(options) {  
            this._super('initialize', [options]);  
            this.custom_value = App.config.custom_parameter;  
    } 
    

    and I found that it not change value immediately when we change in config_override until we repair and rebuild.

    Is there solution for change value immediately, no need repair and rebuild ?

  • From what I was able to see in the source code, those 'additional_js_config' only become available in the JS when you perform Quick Repair & Rebuild or when you clean the cache directory.

  • Thank you for explain, I got it.