Skip to main content
14-Alexandrite
July 18, 2016
Solved

ConfigurationTables Choice List - is it possible?

  • July 18, 2016
  • 4 replies
  • 2183 views

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

Best answer by thearonh

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" })

    }))

})

4 replies

thearonh5-Regular MemberAnswer
5-Regular Member
July 19, 2016

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" })

    }))

})

emoreira14-AlexandriteAuthor
14-Alexandrite
July 19, 2016

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" })

     }))

  })

5-Regular Member
July 19, 2016

That is good to know!  I wasn't aware it would work using either the key or value as default - thanks for the input!

5-Regular Member
July 20, 2016

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