4 Replies Latest reply on Jul 20, 2016 9:58 AM by supandey RSS
    ewertonm Creator

    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

      • Re: ConfigurationTables Choice List - is it possible?
        thearonh Apprentice

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

            }))

        })

          • Re: ConfigurationTables Choice List - is it possible?
            ewertonm Creator

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

                 }))

              })

             

          • Re: ConfigurationTables Choice List - is it possible?
            supandey Collaborator

            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