Implement Services, Events, and Subscriptions Guide Part 2
/ Provide your filter using the format as described in the help topic "Query Parameter for Query Services" var query = { "filters": { "type": "EQ", "fieldName": "CustomerId", "value": CustomerId } }; // result: INFOTABLE dataShape: "" var result = Things["PackageDataTable"].QueryDataTableEntries({ maxItems: undefined /* NUMBER */, values: undefined /* INFOTAB
After saving changes and closing the Service edit view, you can test the method by selecting the Execute play button.
The Service we created will query PackageDataTable for any packages with the CustomerId you entered. If no data has been added to the DataTable as yet, open PackageDataTable's Services tab and execute the AddDataTableEntries Service with test data.
Step 6: Create Subscriptions
Subscriptions are based on tracking the firing of an Event. When the Event is triggered or fired, all entities with a Subscription to the Event will perform the script as defined. The JavaScript interface and script tabs are the same as those utilized for the Services interface.
Subscriptions are a great resource for making updates in other Entities, Databases, or even just logging this information to your liking.
- On the home page, filter and select the PTCDeliversBusinessLogic Thing.

- Switch to the Subscriptions tab.
- Click + Add.

- For Source, select *Other Entity.
- Filter and select PackageStream.
- Check the Enabled checkbox.
Using a Stream to track events in the application allows for one source to watch for activity. The source for a Subscription can be other Entities if a single Entity is wanted. In order to capture all source data from the PackageStream, you will need to set it as the Stream for the Entity you would like to track.
- Switch to the Inputs tab.
- Select the Event drop-down and pick the PackageDelivered Event. This PackageDelivered Event only exists in the completed download. If you are not using that download, create your own Event based on the PackageDataShape.

- Update the script area of the Subscription using the below code. This JavaScript code will take the information from the triggered Event and add it to the DeliveryDataTable.
/ tags:TAGS
var tags = new Array();
// values:INFOTABLE(Datashape: PackageDataShape)
var values = Things["DeliveryDataTable"].CreateValues();
values.Customer = eventData.Customer; // THINGNAME
values.Content = eventData.Content; // STRING
values.ID = eventData.ID; // INTEGER [Primary Key]
values.Weight = eventData.Weight; // NUMBER
// location:LOCATION
var location = new Object();
location.latitude = 0;
location.longitude = 0;
location.elevation = 0;
location.units ="WGS84";
var params = {
tags : tags,
source : me.name,
values : values,
location : location
};
// AddOrUpdateDataTableEntry(tags:TAGS, source:STRING("me.name"), values:INFOTABLE(DeliveryDataTable), location:LOCATION):STRING
var id = Things["DeliveryDataTable"].AddOrUpdateDataTableEntry(params);
Step 7: Next Steps
Congratulations! You've successfully completed the Implement Services, Events and Subscriptions guide.
In this guide you learned how to to create Events, Services and Subscriptions you can utilize to monitor and optimize your IoT applications.
The next guide in the Design and Implement Data Models to Enable Predictive Analytics learning path is Build a Predictive Analytics Model.
The next guide in the Monitor Factory Supplies and Consumables learning path is Build a Predictive Analytics Model.
Learn More
We recommend the following resources to continue your learning experience:
Capability Guide
| Build | Create Custom Business Logic Guide |
| Secure | Configure Permissions |
| Connect | SDK Reference |
Additional Resources
If you have questions, issues, or need additional information, refer to:
Resource Link
| Community | Developer Community Forum |
| Support | Help Center |








