Using constant value in another constant

0
How can I use the value of a constant in another constant. For example: let's say I have a constant called country with the value India, and another constant called city. I want to declare the value of city such as: Hyderabad, @MyFirstModule.Country. Now, every time I change the value of the country, the value of City should change accordingly. In this example, if I change the value of country to Pakistan, then the value of city should evaluate to Hyderabad, Pakistan (from Hyderabad, India).
asked
3 answers
0

Hi Sajjad,

Constants can't be changed at run time. You would have to change the value in the sprinter portal and then restart your environment for the new values to take effect.

Here is some documentation on constants

https://docs.mendix.com/refguide/constants

 

From what you explained in your question, it sounds like you would need to use an enumeration. You would create an entity that had an attribute called "Country" and another attribute called "City". Both attributes would be of type enumeration and you would be able to define the list of possible values in the modeler. Then in a microflow or on a page you could change or edit this record based on the value of "Country".

Here is some documentation on enumerations

https://docs.mendix.com/refguide/enumerations

 

Hope this helps!

 

answered
0

Unfortunately, this doesn't answer the query. I know about enumerations. But that's not what I'm looking for. I'm not trying to define an enum of Countries and Cities. Let's say this particular City and Country is to be used in displaying somewhere in the app. I'm not concerned with all the Cities and Countries of the world. I need to display the values of these constants which are configured in the environment settings. Based on which client is using the app, the client should be able to configure the City and Country.

 

My concern was how can I make the value of these configuration settings be read from one another. This is similar to how we can declare properties in a Spring application.

 

Further, I understand, once the application starts, these values cannot be changed without rebooting the application.

answered
0

Your best solution would be to use the Deploy API to programatically set the values of your constants, using the GetEnvironmentSetting and SetEnvironmentSettings operations.

answered