Preference Page Input Options from a Map or array

smartapp

(Yogesh Mhatre) #1

Im trying to pull options which are key set from a MAP and display then in the Preferences page for users to select. However, I always get no options when I install the app, thought I can throw them in logs before. Here’s my Prefence page

preferences {
    page(name: "credentials", title: "Welcome") 
    page(name: "locationList", title: "Location for this App", nextPage: "success", content:"locationList")
    page(name: "success")  

private locationList(params=[:]){
    def locations = locationFound() // Executes locationFound() that returns a map of locations, example  [Home:098765, Office:123456]
    def options = locations.keySet() ?: [] // log.debug options =  [Home, Office]
    return dynamicPage(name:"locationList", title:"Pulling up the Location List!", install: true, uninstall: true) {
    	section("Select from the following Locations") {
    			input "selectedLocation", "enum", required:true, title:"Select the Location", multiple:false, options:options
    		}
    	}
    }

At this point, Im expecting my preference page would give me both the options to select. However I get a message “No available Options”. Am I doing something weird while defining the options in dynamicPage.


(Yogesh Mhatre) #2

I should add, that this when I ran in a simulator works well. But on my phone (iOS device) this shows no options available. Is there a problem with type “enum”


(Yogesh Mhatre) #3

Interesting … I bypassed the Elvis Operator and directly called locations in the options and now this works. Though I only get the location number, instead of the name.


(Yogesh Mhatre) #4

Fixed this, by eliminating elvis operator and using “as List”

    def optionList = locations.keySet() as List
    log.debug optionList
	return dynamicPage(name:"locationList", title:"Pulling up the Location List!", uninstall: true) {
		section("Select from the following Locations.") {
			input(name: "selectedLocation", type: "enum", required: true, title: "Select the Location", options:optionList, multiple: false)
		}
	}
}