Hi @jelle, naturally FME Server parameters won't be defined in Desktop environment, so the FME_MacroValues dictionary may not have the key (parameter name) and value pairs for those parameters. I think you encountered KeyError from the Python interpreter.
There are at least two workaround.
1. Use the 'in' operator to determine if the dictionary contains the key. If the key doesn't exist, do something you need.
or
2. Use the 'get' method of dict class to get the value. The method returns default value if the key doesn't exist, so you can determine if the key exists based on the return value.
Hi @jelle, naturally FME Server parameters won't be defined in Desktop environment, so the FME_MacroValues dictionary may not have the key (parameter name) and value pairs for those parameters. I think you encountered KeyError from the Python interpreter.
There are at least two workaround.
1. Use the 'in' operator to determine if the dictionary contains the key. If the key doesn't exist, do something you need.
or
2. Use the 'get' method of dict class to get the value. The method returns default value if the key doesn't exist, so you can determine if the key exists based on the return value.
Hi Takashi, thank you for your answer. I was already looking in the direction of the get method. Combined with your answer on
Multiple Parameters, I was able to solve my challenge. Learned again something today.
First, I create a parameter Get_Hostname
if FME_MacroValues.get('FME_SERVER_HOST', None):
print 'Server'
return FME_MacroValues['FME_SERVER_HOST']
else:
print 'Desktop'
global FME_MacroValues_Desktop
FME_MacroValues_Desktop = {'FME_SERVER_HOST':'YYYYYYYYY'}
return FME_MacroValues_Desktop['FME_SERVER_HOST']
Then, I have a second parameter called FME_Connection
if FME_MacroValues.get('FME_SERVER_HOST', None):
_hostname = FME_MacroValues['FME_SERVER_HOST']
else:
_hostname = FME_MacroValues_Desktop['FME_SERVER_HOST']
if _hostname == 'XXXXXXXXX':
FME_Connection = 'fmeserver_prod'
else:
FME_Connection = 'fmeserver_dev'
return FME_Connection
Based on the FME_Connection parameter, I set some other parameters like E-mail addresses to send an e-mail to and the WebService URL I want to use in the HTTP Caller.
I hope this example helps for other people as well.