New BaseType Function and workaround solutions
Dear Community,
I am building a Template for Things to periodically read and buffer data. In my configuration I maintain a list of properties to read on every timer event, it basically looks like this
| Id | Property |
| 1 | Status |
| 2 | Speed |
| ... |
Unfortunately only the property alone is not enough information, I may have more complex access patterns (e. g. reading from an InfoTable), conversions, checks, etc. Hence my idea is to provide the function code along with the property in the configuration, like this
| Id | Property | Access function |
| 1 | Status | function f() {return me.Status;} |
| 2 | Speed | function f() {return Math.abs(me.Speed);} |
| ... |
Using Thingworx 8.4.4 I have not found a datatype to hold the function code. Any chance we would get something like that one day? Or is it even available in later Releases?
I can think of two possible workarounds.
1. Store the code as string and run with eval.
I am not going to do that because one should never use eval. Additionally I am not sure about performance if the functions have to be parsed every time.
2a. Put the code in a separate Service and put the Service name into the configuration.
2b. Put all code in one Service and use switch command based on the property name.
I am working on this at the moment, probably I will prefer 2b. On the downside I am losing the desired flexibility because all access functions have to be available as code on my Template. It is not possible to dynamically extend my configuration without adding code to my Template.
Would be happy to get some thoughts.
Thank you
Benny
