I tried to change the value of global variable like that:

public static void updateGlobalVariableValue(final String globalName,final String globalValue,final IEnvironment environment) throws Exception {
    SecurityManagerFactory.getSecurityManager().executeAsSystem(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            IGlobalVariable variable = environment.findGlobalVariable(globalName);

            if (variable != null) {
                variable.setValue(globalValue);
            }

            return null;
        }
    });
}

If in the selected environment, we didn't set the value of that variable, after execute my function, the default value of the global variable is changed.

Is it a bug of API or I did the wrong way? Could you please show me the way to modify just the value of global variable in the selected environment and keep the default value?

Thank you very much, Phu Nguyen

asked 03.01.2014 at 10:59

anphunl's gravatar image

anphunl
(suspended)
accept rate: 50%

edited 03.01.2014 at 10:59


If no value is configured for a environment for a global variable then the method IEnvironment#findGlobalVariable will return the default configuration of a global variable (e.g. default environment) as noted in the javadoc. If so and you set the value of it you change the default value.

Use method IApplication.findDefaultGlobalVariable(String environment) to get the default configuration (e.g. default environment) of a global variable. On the default configuration you can call findEnvironmentConfiguration(String environment) to get the configuration of the global variable for a specific environment. If it does not exists null is returned. Use method createEnvironmentConfiguration(...) to create a missing configuration for a global variable for a specific environment.

link

answered 06.01.2014 at 16:26

Reto%20Weiss's gravatar image

Reto Weiss ♦♦
4.9k202857
accept rate: 74%

Thank you very much for your answer. I did it like that :

IGlobalVariable variable = environment.findGlobalVariable(globalVariableName);

if (variable != null) {
    if (variable.getDefaultGlobalVariable() != null) {
        variable.setValue(newValue);
    } else {
        environment.createGlobalVariable(variable.getName(), variable.getDescription(), newValue);
    }
}
(07.01.2014 at 04:13) anphunl anphunl's gravatar image

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×6

Asked: 03.01.2014 at 10:59

Seen: 3,751 times

Last updated: 07.01.2014 at 04:13