1 Reply Latest reply on Apr 1, 2016 12:14 PM by pchung RSS
    leisel Explorer

    Script for a Service that changes the property values of the Things inside an InfoTable

    I have a selection of Sensors for a User to choose. The User can create a grouping of whatever order of sensors, called a 'Scene'. These Scenes share the same SceneTemplate and the property that stores the Sensors they chose is an InfoTable, called "DeviceList".

     

    • Goal: What I wanted to do was let a User choose one of their created Scenes, and use a Button to call a service that allows that Scene's Sensors "OnOff" property to be set to On, subsequently having non-included sensors turned Off.

     

    I'm stuck on figuring out the best way to implement that. I assume I would have to create my own service.

     

    The service I will need to make must access all implemented things of my SensorTemplate and also access the DeviceList of the User-selected Scene, and then access the properties of the Sensors, comparing which Sensors of SensorTemplate are and aren't inside DeviceList so their property can be correctly set On or Off.

     

    I'm guessing it should be a service for my SensorTemplate and it wouldn't necessarily need a return value, but other than that I haven't found a useful tutorial for writing my own script for a service. For example, I know how to find the function "GetImplementedThings" for my SensorTemplate inside the script, but am unsure how I could use it's return value(InfoTable) to do further work in the script and eventually change property values.

     

    Any kind of webpages, tutorials, or advice would be appreciated. Thank You

      • Re: Script for a Service that changes the property values of the Things inside an InfoTable
        pchung Collaborator

        I recommend the Thingworx Fundamentals course.

        Your explanation is somewhat complicated for me to understand exactly what you are doing, but sounds like you have a good idea and are on the right track.

        Services are all javascript and Thingworx provides snippets and default services for you to be able to do what you need to do, either BI or in your case retrieval of 'assets' Each of these snippets and services and the services you create have return type, an InfoTable is basically an array and you can address information inside of it using result.name for example to get the entity name. (You can figure out the fields within it, by checking the datashape, or just testing the service)