Hi Guys Is it possible to use variables inside th...
# cfml-general
c
Hi Guys Is it possible to use variables inside the CF Admin GUI? I saw this:
Copy code
[refer to image attachment]
It seems that: > { application.home } Is referring to a variable of some sort? Do you know where I would set a new placeholder variable, like: > { application.dsnHost } I have 300 DSNs and I don't want to change each one, every time I switch DB servers? I have searched in:
Copy code
\\wsl.localhost\Debian\opt\coldfusion2018\cfusion\runtime\conf\server.xml
\\wsl.localhost\Debian\opt\coldfusion2018\cfusion\runtime\conf\web.xml
But I cannot find anything?
r
I'm not sure if you can add anything but application.home is set in the CFROOT\INSTANCE\bin\jvm.config file.
j
Not sure if your particular datasources can be configured/altered this way, but using the cfsetup CLI tool ( https://helpx.adobe.com/coldfusion/using/cfsetup-configuration-tool.html ) may be one way to export settings and then re-import them after a global search/replace.
r
Unfortunately, that tool doesn't work with ACF2018 and prior versions.
m
is there any qualms to utilizing commandbox and cfconfig ...
☝️ 1
d
How about setting them procedurally in application.cfc? Don't remember for sure if that's supported for 2018, but I think so. Out of curiosity, why so many DSNs? Are you a hosting provider or something? We have "a lot", but not close to that many, and we already don't like it. Keeping our ducks in a row across multiple dev, stage, and production environments is Not Fun (tm). We have an environmentConfiguration.cfm file, called by application.cfc, that sets those and other stuff according to the domain being accessed.
c
OK. I did try adding a new entry to `CFROOT\INSTANCE\bin\jvm.config`:
Copy code
java.dsnHost=<http://foo.rds.co.uk|foo.rds.co.uk>
And then I added
{application.dsnHost}
to the correct place, but the verification failed. So, clearly it didn’t work. In the end, I just did a find/replace on the host name in `neo-datasources.xm`l and then swapped over the old file with the new file and everything works. In future, I just need to switch between the two
neo-datasources.xml
files to achieve what I need. But thanks for the help everyone. It would be really great, in a future release of Coldfusion, if they could add the following feature: Add a section called CF Admin Variables, where we can set placeholder variables that can be used all over the CF Admin GUI 🙂
r
Shouldn't that be
application.dnsHost=<http://foo.rds.co.uk|foo.rds.co.uk>
?
c
Hmmm. Well, all the other variables in the
jvm.config
file, use the java scope?
Like: jvm.config
Copy code
#
# VM configuration
#
# Where to find JVM, if {java.home}/jre exists then that JVM is used
# if not then it must be the path to the JRE itself

java.home=/opt/coldfusion2018/jre
I guess somewhere, the
java
scope is converted into the
application
scope?
r
Hmm, seems to be something with multiple instance install. I see
application.home=C:/ColdFusion2021/instance_name
just before Arguments to VM section.
c
Yes. But I cannot see:
Copy code
application.home=
Anywhere, in that file?
r
Yes, it doesn't appear to be in the default instance on a multiple server install or in a single server install.
👍 1
c
I can see it read, in a few places, but I cannot see where it is written, so I presumed that:
Copy code
java.home
Was being used, instead?
The only issue, is that I can only see:
Copy code
application.home
Used in the Server Settings -> Java and JVM section of the Coldfusion Administrator GUI So maybe, that
java
scope is only picked up in that section and cannot be used in Data & Services section
I do remember in Lucee that a placeholder variable is used in the Server Settings -> mapping section, so I am not sure about my last comment?
I just wished there was some documentation on this topic, because it would be very useful to be able to set placeholders variables in the ColdFusion Administrator, especially in the Data & Services section, where repetition is prevalent. At one company I worked for, they had 600 DSNs and three different DB server hosts. Imagine just being able to change a single variable, rather than 600 hard coded values. I mean clearly the ACF team have already implemented this methodology, so why not let all of us, use it? It would just require a couple of form fields [variable name/variable value] & a CRUD table below. Then it could be integrated into whatever the
java
scope does?
r
Yeah, I couldn't find any documentation either.
c
This really feels like it would be worth exploring defining datasources using
this.datasources
in your
Application.cfc
. You could set environment variables in your OS or in your jvm.config file to define the "global" variables, then access them when defining the datasources in
Application.cfc
. This allows for having different values for the "global" variables on different servers (development/testing/staging/production) without having to alter your CFML code. Defining multiple datasources this way has been supported since CF 11. Alternatively, as previously mentioned by @Michael Schmidt, you can use CommandBox and the CFConfig module to export/import the configuration settings that you typically use ColdFusion Administrator to manage. You could export just the database connections, edit them in a text editor, and then reimport them back into ColdFusion. This does not require you to use CommandBox to start/stop servers. You can use it just for this purpose if you want.
👍 1
b
This sounds like a job for CFConfig, TBH
You can use CFConfig even on non-Commandbox servers
You can fully script everything, it works back to CF9, and we support all manner of replacements in the JSON files
Or you could just script the CLI calls
Or you could write a task just scripting the service API directly
👏 1