Skip to main content
1-Visitor
April 10, 2018
Question

Create and use "enum" type properties

  • April 10, 2018
  • 1 reply
  • 3104 views

Hello,

I would like to have something like 'enum' (similar to ones in C/C++) in Thingworx. And then to create a 'property' of that 'enum' type, which can hold only one of the 'enum constants' defined for that 'enum', at a particular time.

Is that possible to achieve something like that?

My basic requirement is to create a 'stateDefination' variable, which supposedly would be the created 'enum' type property, and on running various services on the Thing, this variable would change its state.

Any suggestions or ideas are welcome.

I also found a similar post with same requirement, but since it was very old, I am looking if any new provisions are introduced in Thingworx to achieve this.

 

https://community.ptc.com/t5/ThingWorx-Developers/Best-Practice-for-using-an-enumerated-type/td-p/513007

 

I am looking for something similar to technique used for defining BaseTypes in Thingworx.

 

Thanks in advance

Regards

Aditya Mittal

1 reply

1-Visitor
April 11, 2018

Latest answer by Jason answer on the previous post it's the correct one

amittal-31-VisitorAuthor
1-Visitor
April 11, 2018

Hello Carles,

I understood what Jason might have done to achieve the required feature, maybe I can also try to mimic his solution. But I just had one concern, that my basic purpose of using this 'enum' was to make easy and fast assignments and comparisons. However, if I have many such comparisons in my service, they would actually be string comparisons and could be time consuming operation (as compared to int comparison).

I am also thinking, that maybe I can create my "ENUM THING" (since thing is also a kind of user defined data type/class) which will hold the properties (of type integer) with name of enum aliases, and their values as enum constants. Then I can use that "enum thing" across my services as it would be a unique global thing.

This is just a thought.

Regards

Aditya

1-Visitor
April 11, 2018

Hello Aditya,

 

We already have a similar solution with what you are proposing, implemented with DataTables that contain String Values for ID Values and automatically shows up as DropDown widgets on properties which has "enum type" assigned. Everything relay on a ThingShape which takes care of enforcing "enum types" and showing the corresponding DropDown.

 

We call it Referential Integrity on traditional DataBases 😉 and this is what we had implemented for ThingWorx Properties.

 

Best Regards,

Carles.