<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to change the value of global variable of a selected environment programmatically and keep the default value?</title><link>https://answers.axonivy.com/questions/227/how-to-change-the-value-of-global-variable-of-a-selected-environment-programmatically-and-keep-the-default-value</link><description>&lt;p&gt;I tried to change the value of global variable like that:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public static void updateGlobalVariableValue(final String globalName,final String globalValue,final IEnvironment environment) throws Exception {
    SecurityManagerFactory.getSecurityManager().executeAsSystem(new Callable&amp;lt;Void&amp;gt;() {
        @Override
        public Void call() throws Exception {
            IGlobalVariable variable = environment.findGlobalVariable(globalName);

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

            return null;
        }
    });
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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?&lt;/p&gt;
&lt;p&gt;Thank you very much,
Phu Nguyen&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/227/how-to-change-the-value-of-global-variable-of-a-selected-environment-programmatically-and-keep-the-default-value" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 07 Jan 2014 04:13:26 -0500</lastBuildDate><item><title>Comment by anphunl on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/227/how-to-change-the-value-of-global-variable-of-a-selected-environment-programmatically-and-keep-the-default-value#230</link><description>&lt;p&gt;Thank you very much for your answer.
I did it like that : &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;IGlobalVariable variable = environment.findGlobalVariable(globalVariableName);

if (variable != null) {
    if (variable.getDefaultGlobalVariable() != null) {
        variable.setValue(newValue);
    } else {
        environment.createGlobalVariable(variable.getName(), variable.getDescription(), newValue);
    }
}
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">anphunl</dc:creator><pubDate>Tue, 07 Jan 2014 04:13:26 -0500</pubDate><guid>https://answers.axonivy.com/questions/227/how-to-change-the-value-of-global-variable-of-a-selected-environment-programmatically-and-keep-the-default-value#230</guid></item><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/227/how-to-change-the-value-of-global-variable-of-a-selected-environment-programmatically-and-keep-the-default-value/229</link><description>&lt;p&gt;If no value is configured for a environment for a global variable then the method &lt;code&gt;IEnvironment#findGlobalVariable&lt;/code&gt; 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.&lt;/p&gt;
&lt;p&gt;Use method &lt;code&gt;IApplication.findDefaultGlobalVariable(String environment)&lt;/code&gt; to get the default configuration (e.g. default environment) of a global variable. On the default configuration you can call &lt;code&gt;findEnvironmentConfiguration(String environment)&lt;/code&gt; to get the configuration of the global variable for a specific environment. If it does not exists null is returned. Use method &lt;code&gt;createEnvironmentConfiguration(...)&lt;/code&gt; to create a missing configuration for a global variable for a specific environment.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Mon, 06 Jan 2014 16:26:58 -0500</pubDate><guid>https://answers.axonivy.com/questions/227/how-to-change-the-value-of-global-variable-of-a-selected-environment-programmatically-and-keep-the-default-value/229</guid></item></channel></rss>