Appsettings not accessible

I have defined appSettings in my smartApp

        appSetting "appId"
        appSetting "apiToken"

Though, appSettings variable is accessible anywhere but I can’t access my appId from it. I get the error
java.lang.NullPointerException: Cannot get property 'appId' on null object @line 24 (run) on accessing appSettings.appId.
However, I can also access the same inside initialize() function. Why can’t I access specific setting but can very well access appSettings variable as a whole?

Have you set a value for appId in the SmartApp properties?

1 Like

Yes, the value is already set. I can even access that value in initialize() function scope.

Try using a different name than “appId” – I think that is quite possibly a reserved word.

Another workaround is to copy it to the settings.* map in your initialize() method.


This line works fine inside an arbitrary method in one of my SmartApps:

def map = [
			uri: appSettings.apiPath + "/stuff.cgi?auth=${appSettings.apiKey}", 

Thanks for the workaround but the workaround to copy it to the settings.* map in my initialize() method won’t benefit me as I want to acces it in preferences block. Also, I can get the value in any method, just not outside it. Is there any way to access the value in preferences block.

1 Like

Ah… Preferences! … That’s the detail I was missing!

There are tremendous limitations as to what objects/variables are available in preferences{}. Preferences are actually metadata and not Groovy code / methods. This section is parsed by a preprocessor and/or rendering layer.

I frankly don’t think you can access appSettings within preferences{}. Along with a lot of other things you can’t do in preferences.

Carefully study the documentation section on Dynamic Preferences, just in case I’m missing something obvious. Dynamic Preferences are powerful, but still limited - and I’m not sure all the limitations are clearly documented:

BTW: You’re also more likely to get a helpful answer here if you detail exactly what your goal is, rather than just the syntax you are attempting to use.

  • Why do you need appsettings in Preferences?
1 Like