ConfigurationTables Choice List - is it possible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
ConfigurationTables Choice List - is it possible?
Hello All,
I am working in an extension that will create a ThingTemplate with some configuration fields and I would like to provide a list of choices instead of a free text input.
I am also considering making it a boolean field if I have only 2 choices but most likely I will have 3 choices and I'd like to provide the options and also the default values
The sample code helped me to create the config table:
Any Thoughts?
Cheers
Ewerton
Solved! Go to Solution.
- Labels:
-
Extensions
- Tags:
- extension sdk
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
There is a way to do this - the 'selectOptions' aspect in the ThingworxFieldDefinition annotation. The syntax is a little tricky, with the selectOptions being in a key:value pair notation with a bar splitting the options. The Value is what is shown in the UI in Composer, the Key is what is returned from a selection (also what is used to set the default value). Often times, the Key and Value are the same, just for simplicity, although my example has them different to show the capabilities. Here is the example:
@ThingworxConfigurationTableDefinitions(tables = {
@ThingworxConfigurationTableDefinition(name = "MyConfigTable", description = "", ordinal = 0, dataShape =
@ThingworxDataShapeDefinition(fields = {
@ThingworxFieldDefinition(name = "MyTimePickerField", baseType = "STRING", ordinal = 0, aspects = {
"defaultValue:M",
"selectOptions:S:Seconds|M:Minutes|H:Hours|D:Days|N:Months|Y:Years",
"friendlyName:Time Picker" })
}))
})
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
There is a way to do this - the 'selectOptions' aspect in the ThingworxFieldDefinition annotation. The syntax is a little tricky, with the selectOptions being in a key:value pair notation with a bar splitting the options. The Value is what is shown in the UI in Composer, the Key is what is returned from a selection (also what is used to set the default value). Often times, the Key and Value are the same, just for simplicity, although my example has them different to show the capabilities. Here is the example:
@ThingworxConfigurationTableDefinitions(tables = {
@ThingworxConfigurationTableDefinition(name = "MyConfigTable", description = "", ordinal = 0, dataShape =
@ThingworxDataShapeDefinition(fields = {
@ThingworxFieldDefinition(name = "MyTimePickerField", baseType = "STRING", ordinal = 0, aspects = {
"defaultValue:M",
"selectOptions:S:Seconds|M:Minutes|H:Hours|D:Days|N:Months|Y:Years",
"friendlyName:Time Picker" })
}))
})
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thanks Thearon, that did the trick.
It is actually quite simple once you get the syntax right! The only comment is that I actually put the VALUE in the default value field and it worked.
@ThingworxConfigurationTableDefinitions(tables = {
@ThingworxConfigurationTableDefinition(name = "MyConfigTable", description = "", ordinal = 0, dataShape =
@ThingworxDataShapeDefinition(fields = {
@ThingworxFieldDefinition(name = "Port 1", baseType = "STRING", ordinal = 0, aspects = {
"defaultValue:INPUT",
"selectOptions:I:INPUT|O:OUTPUT|P:PWM",
"friendlyName:PORT 1" })
}))
})
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
That is good to know! I wasn't aware it would work using either the key or value as default - thanks for the input!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi guys, thanks for the great question and answer on this topic. To increase it's reach I have converted this thread to a technical article with title : How to create choice list which include list of options with different datatype values under PTC Technical Support site to help others requiring this information such as myself
If you happen to have any feedback concerning the article's content or its structure or just in general i'd be happy to hear it. Feedback on the article could be submitted directly from the article itself or here within the thread.
Sushant
