Automate business processes with Services, Events and Subscriptions.
This project will introduce Services, Events, and Subscriptions inside of the ThingWorx platform.
Following the steps in this guide, you will be able to expand your data model using Services, Events, and Subscriptions.
We will teach you how to make a more robust and enjoyable experience for users simply by using the resources inside of the ThingWorx Composer.
NOTE: The estimated time to complete this guide is 60 minutes
This guide references the attached EventsServicesSubscription.zip. The sample application is based on a company needing to make deliveries. The rules engine will handle much of the work outside of the transportation workflow.
Unzip and utilize this file to see a finished example and return to it as a reference if you become stuck during this guide and need some extra help or clarification.
Keep in mind, this download uses the exact names for entities used in this tutorial. If you would like to import this example and also create entities on your own, change the names of the entities you create.
Name Type
PTCDelivers | Thing |
PTCDeliversBusinessLogic | Thing |
PackageStream | Stream |
OrdersDatabase | Database |
DeliveryDataTable | Database |
PackageDataTable | Database |
MerchantDatabase | Database |
PlaneThingTemplate | ThingTemplate |
MerchantThingTemplate | ThingTemplate |
TruckThingTemplate | ThiingTemplate |
ClientThingShape | ThingShape |
VehicleDeliveryShape | ThingShape |
PackageDataShape | DataShape |
CustomerDataShape | DataShape |
OrderDataShape | DataShape |
PackageDeliveryDataShape | DataShape |
MerchantOrderDataShape | DataShape |
MerchantDataShape | DataShape |
default_user | User |
TestDashboardMashup1 | Mashup |
TestGadget | Mashup |
You can combine Services, Subscriptions, and Events to automate business processes or trigger notifications. See the definitions and examples before to gain a better understanding as to the role each plays.
Name Function
Services | Methods and functions to be used within a ThingWorx application. There are Services provided by the system, but custom services need to be made to create the application's functional requirements. All services in the ThingWorx Composer can be accessed by a user with the appropriate permissions. Remote services can be created with the use of the ThingWorx SDKs. |
Events | An Event represent a change in state of a property or changes in a running application. Changes can be handled in different ways based on the method used to fire or queue them. They are a great resource for property value changes and alerts. |
Subscriptions | The implementation for a subscription is the same as that of a service. Subscriptions are activated when the Event they are listened for is triggered. |
Events are used to mark situations that can occur within an application. They can be used for scenarios ranging from a dangerous situation that is imminent and needs to be checked by personnel to just a system notification. Each Event is based on a DataShape that will hold the necessary information about the Event.
For example, it wouldn’t be enough to just know that a rain Event has occurred. It might be helpful to also know the location, the time the rain started and expectations of the amount of rain to fall.
Follow the steps below to create an Event for the TruckThingTemplate Entity.
Events can be queued or fired based on updates done in Composer, property changes of a running application, or programmatically. Triggering or firing an Event can be done in Services utilizing JavaScript.
To create Services within ThingWorx, go to the Services tab of the Entity that will house the Service. Our PTCDeliversBusinessLogic Thing will contain several Services for us.
Within the Services tab under the Entity Information section of a Thing, you will see built in functionality for all the ThingTemplates and ThingShapes the Thing inherits from. You will also see the section that allows you to create new Services.
This tab is for the general information of the Service. This is where you will add the Service name, description, category, whether the service is asynchronous, and whether the Service can be overridden.
This tab is for the parameters for the Service. For input parameters, a parameter can be required and default values are allowed.
This tab is for the return type of the Service. The resulting output of the Service can stretch from being nothing to user defined Entities.
This tab allows users to pick from reusable JavaScript code that is specific to ThingWorx. These snippets are grouped by resources used, functionality, and type. You are also provided a search bar to look for keywords or titles.
When a snippet is found, click the arrow. This will insert the JavaScript code into the Script section wherever the cursor is located. From here, edit the inserted snippet to work with the rest of your code. This section is often helpful in getting to know how to perform service calls and code for the ThingWorx environment.
A listing of all Properties, Events, and Services belonging to custom and provided Entities in ThingWorx. As with the Snippets section, clicking the blue and white arrow will insert the reusable code to wherever the cursor is located. After the code is inserted, update the code to your liking. This is often a great resource for buildiung up payload for Service calls.