cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

ConfigurationTables Choice List - is it possible?

emoreira
12-Amethyst

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

    }))

})

View solution in original post

4 REPLIES 4

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

    }))

})

emoreira
12-Amethyst
(To:thearonh)

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

     }))

  })

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

supandey
19-Tanzanite
(To:emoreira)

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

Top Tags