Skip to main content

Lately I have been working a lot with Postman. One of the nice features of this tool is that you can define environments, e.g. development and production. For each environment you can define it's own set of parameter values. So when you switch between development and production, the values for the url, userid and password are automagically changed also.

How can I achieve this same behaviour in FME? I would like to have a published parameter that lets me choose between development and production and subsequently sets the correct values for url, userid, password and possibly other parameters.

I fixed this using scripted parameters. See this topic.


I used Python scripted parameters too.

Use 1 published parameter (Environment: Choice with alias).

Then add Private (non published) scripted Python parameters that use the value of the published Environment parameter to set the required parameters like URL, USER, PASSWORD etc.


Thank you @erik_jan and @nielsgerrits! Your answers are really helpful.

 

I created a published parameter environment (choice with alias, values prod and test) and two private parameters: url_prod and url_test.

Then I created a third private parameter url, a scripted Python parameter with this code:

import fme
env = fme.macroValues.get('environment')
if env == 'prod':
    return fme.macroValues.get('url_prod')
elif env == 'test':
    return fme.macroValues.get('url_test')

This works fine, but gets a little bit messy if I have more parameters to set and even more values to choose from.

In the example I would rather have only one private parameter. This would be url (choice with alias). I would like to select the right value based upon the value of the published parameter environment.

Is it possible to set the value of a private parameter at runtime? What would the Python code look like?


If you can use Web Connection authentication, then you can create a connection per environment and just switch as necessary.

For example, if you are literally moving the FME workspace to a different machine, then on each machine you can create a connection called MyConnection (for example). On Machine A the parameters in MyConnection point to the development environment. On Machine B the parameters in MyConnection point to the production environment. When you move the workspace from Machine A to B, because the connection name is the same, it will just use the new connection parameters.

If you are staying on the same machine, but pointing to different environments, then you would need to create two connections: MyConnectionDev and MyConnectionProd. To switch environments you just switch the connection. As long as that same connection is shared wherever it is needed in the workspace, then switching the connections switches everywhere it is used.

I realize that this is only for ID/passwords - not URLs as you mentioned - but I think it is a useful option to be aware of.

Re your second question, if you have Choice with Alias and it returns either Dev or Prod then everywhere you use it needs to be those values (Dev or Prod) otherwise you are going to need Python parameters as you already defined. How many environment values do you need to set? If it's just ID, Password, and URL then I'd use a predefined connection (as above) for ID/Password, leaving just URL to be set with a script.


If you can use Web Connection authentication, then you can create a connection per environment and just switch as necessary.

For example, if you are literally moving the FME workspace to a different machine, then on each machine you can create a connection called MyConnection (for example). On Machine A the parameters in MyConnection point to the development environment. On Machine B the parameters in MyConnection point to the production environment. When you move the workspace from Machine A to B, because the connection name is the same, it will just use the new connection parameters.

If you are staying on the same machine, but pointing to different environments, then you would need to create two connections: MyConnectionDev and MyConnectionProd. To switch environments you just switch the connection. As long as that same connection is shared wherever it is needed in the workspace, then switching the connections switches everywhere it is used.

I realize that this is only for ID/passwords - not URLs as you mentioned - but I think it is a useful option to be aware of.

Re your second question, if you have Choice with Alias and it returns either Dev or Prod then everywhere you use it needs to be those values (Dev or Prod) otherwise you are going to need Python parameters as you already defined. How many environment values do you need to set? If it's just ID, Password, and URL then I'd use a predefined connection (as above) for ID/Password, leaving just URL to be set with a script.

Of course, the other option is to not use Python parameters, but do the work in the workspace using attributes. So if the Choice with Alias returns either Dev or Prod, then you just have that parameter and in your workspace deal with the lookup.

eg in the HTTPCaller you could set up the URL as a Conditional Value. The condition could be If parameter = Dev then URL = x, else URL = y.

Not necessarily as good as a parameter, because it's then not reusable throughout the workspace, but it does avoid scripting anything or creating multiple private parameters.


Reply