How to list all constants and their current values?

0
Without knowing in advance what constants are available in my app, I want to get a list of all the constants and their values. Is there a way to do that/ Use case: I want to make a snapshot of all of their values every time the app restarts. And if anybody adds a new constant, it should become part of the next snapshot automatically. At every app-restart we store all constants and their value and thus you can see the history of the constant’s values.
asked
4 answers
5

You can get all the constants that are marked as public by calling Configuration.getPublicConstants() in a java activity.

You can retrieve the values using Configuration.getConstantValue(String)

answered
2

Hi Tim,

You could also use the Deploy API to retrieve these for your app(s) and environments. That way you can manage and set them from a single ‘operations’ app?

See Deploy API - APIs & SDK | Mendix Documentation 

answered
1

Hi Tim,

  1. Core API, mentioned by Joost
  2. Deploy API mentioned by Sjors
  3. In your deployment/model folder, you can see config.JSON. May be you can figure out a way to read the file in your server and you can get the list of constants for the latest deployment
  4. But there are some difficulties in handling/managing constants ofcourse. For example, there is no way to set them programmatically except Deploy API. And my try with deploy API was not successful.
    • So, in one of my project, we removed all the constants and saved them as Persistable. So, it is easy for us to manage and maintain also from application point of view. And we were able to make it manageable centralized

 

But it you just want to go with constants, then Deploy API or Config.JSON might be the option.

answered
0

For anyone reading this question looking to do this manually in Studio Pro:

The ‘Find Advanced’ option in Studio Pro can do this for you, this pop up can be reached via the ‘Edit’ drop-down menu or by using Ctrl + Shift + F.

Search for ‘Documents’

Document type 'Constants’

It will show you the default values of the constants, these can of course be set differently for every environment.

answered