Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

ThingWorx Solutions in Food Industry Part 3

100% helpful (1/1)



Step 4: Scheduling Automated Processes


There are many processed that are handled by a corporation. With something as important as food, there is a lot of red tape and regulation.


We will further our Fizos application to monitor food temperatures, expiration dates, product state, and other issues that are factors into the condition of the product. To reduce waste and increase the safety of the food being produced, our application will create entities to model our products after and create a high-level rules engine for the usage and handling of these products.


Let's start with implementing the task of factory inspections. To implement this, we'll use a scheduler to kickstart our daily process and start filling in some of the necessary data.


Schedulers are a great way to execute routine processed. The execute using a configuration similar to that of a cron job on the Linux operating system. In the next guide, schedules will be used to start our deliveries and help execute certain functions of our business logic.


Creating Factories


Before we begin, we'll be using Data Tags. These tags will help organize, filter, search, and analyze what is happening throughout our applications.


  1. In the ThingWorx Composer, click the + New in the top left of the screen.



  2. Select Data Tag in the dropdown.



  3. Set the name as Fizos.FactoryTags.

  4. Set the Project (ie, PTCDefaultProject).

  5. Add new terms now or you can add them later. We'll be adding them later. You can utilize tags with almost anything in this scenario. The more data, the better.



Now let's begin creating the factory data.


  1. Open the Fizos.Factories.DataTable Data Table and go to the services tab.



  2. Open the AddDataTableEntries service to be executed. This service will allow us to create some general data to work with. You can create as many as you like for this test. Click the values parameter to start creating entries.

  3. After clicking + Add, you'll see our Features property. This is where we can find the factory tags we just created, and create as many terms as we like. For simplicity, click New Term create two tags, Sausage and Atlanta. These options will provide us with the purpose of the factory and a location.



4. Save your entry and create a second entry with any location and tags you like. We aren't adding vehicles as of yet, but we will in the next section.

5. After saving, don't forget to execute the service with the two entries saved. If you did it correctly, the values parameter of the service, should show at least a 2 inside of the parentheses. You can also add data to the other parameters if you like. See below:




You now have two factories. We need to inspect these factories daily. What does an inspection entail exactly? You can create custom factories based on the type of products manufactured or have a generic system. Nevertheless, we will log and store these reports in a data table. Let's go.

  1. In the ThingWorx Composer, click the + New in the top left of the screen.



  2. Select Data Shape in the dropdown.



  3. In the name field, enter Fizos.FactoryInspections.DataShape. All of our factory inspections will be based off this Data Shape.

  4. Set the Project (ie, PTCDefaultProject) and click Save to store all changes now.



  5. Add the list of properties below:

Name                      Base Type     Aspects            Description
GUIDStringprimary keyReport identifier
FactoryIDInteger0 minimumFactory identifier
DateRequestDateTimeN/ADate the inspection was requested
DateCompletedDateTimeN/ADate the inspection was completed
ReportJSONN/AThis will hold the inspection report data


The fields for the Fizos.FactoryInspections.DataShape Data Shape are as follows:

  1. In the ThingWorx Composer, click the + New in the top left of the screen.



  2. Select Data Table in the dropdown.



  3. In the name field, enter Fizos.FactoryInspections.DataTable. Our Data Table will hold all of our records on factory inspections.

  4. For the Data Shape field, select Fizos.FactoryInspections.DataShape.

  5. Set the Project (ie, PTCDefaultProject) and click Save to store all changes now.



  6. This entity will be used to house our data and provide assistance with our analytics.

For this scenario, we will create the scheduler that starts a generic process process.

  1. In the ThingWorx Composer, click the + New in the top left of the screen.



  2. Select Schedulers in the dropdown.



  3. Select Scheduler in the pop-up.



4. Name the new Schedule Fizos.Factory.Schedule.

5. For the Run As User field, select the Fizos.Factory.User that was provided in the download.

6. Set the Project (ie, PTCDefaultProject).

7. Click Save and your entity should match the below configuration.



8. For the Schedule field, set it to 0 0 7 * * ?. This will run the process every day at 7 AM. 




9. Switch to the Subscriptions tab and add a new subscription.

10. Name this new subscription PerformDailyInspections and select ScheduledEvent as the event input.




11. Add the following code to the source section:

var factories =  Things["Fizos.Factories.DataTable"].GetDataTableEntries({});
var tableLength = factories.rows.length;

for (var x=0; x < tableLength; x++) {
    var row = yourInfotableHere.rows[x];

        FactoryID: row.ID


This code will execute the inspection request service. Now let's expand on the Fizos.ProductsBusinessLogic to produce and handle the result of a request.

  1. Open Fizos.ProductsBusinessLogic in Edit mode and go to the Services tab.

  2. Open the InspectFactory Service and add the below code. This code will create an inspection request in the data table and you can add code to simulate sending out this request to a user's device or have users query the data table for open requests.

var table =  Things["Fizos.Factories.DataTable"].GetDataTableEntryByKey({
    key: factoryID

var factory = table.rows[0];
var guid = generateGUID();

// Fizos.FactoryInspections.DataShape entry object
var newEntry = new Object();
newEntry.GUID = guid;
newEntry.FactoryID = factoryID;
newEntry.DateRequest = new Date();
newEntry.DateCompleted = undefined;
newEntry.Report = undefined;

var values = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
    infoTableName : "InfoTable",
    dataShapeName : "Fizos.FactoryInspections.DataShape"


    sourceType: "Source Code",
    values: values,
    source: "InspectFactory",

// Use guid for tracking report request
// Create inspection request in ThingWorx attached to guid. This could be stored in a data table or a property field
// Send out employee to factory

3. Open the ReceiveInspection Service and add the below code. This code can be accessed via a REST request to the system. This code can be modified to include error handling and conditions to support new requests coming in.

var table =  Things["Fizos.FactoryInspections.DataTable"].GetDataTableEntryByKey({
    key: guid

var data = table.rows[0];

var update = {};
update.GUID = guid;
update.FactoryID = data.FactoryID;
update.DateRequest = data.DateRequest;
update.DateCompleted = new Date();
update.Report = report;

var values = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
    infoTableName : "InfoTable",
    dataShapeName : "Fizos.FactoryInspections.DataShape"


    sourceType: "Service Code",
    values: values,
    source: "ReceiveInspection"

// Have employee log data using guid
// Track everything inside of logs or data table


You now have a system that will run every day creating requests, storing those requests, and updating those requests with the final reports.



Step 5: Next Steps


Congratulations! You've successfully completed the ThingWorx Solutions in Food Industry guide.

In this guide, you learned how to:


  • Create automated processing, data, and endpoints that can handle that data without manual interaction
  • Use services, alerts, and subscriptions to increase performance
  • Begin making your data model and cornerstone entities to understand how a complex business logic is built


The next guide in the Complex and Automatic Food and Beverage Systems learning path is Factory Line Automation


Learn More


We recommend the following resources to continue your learning experience:


 Capability     Guide
BuildDesign Your Data Model
BuildImplement Services, Events, and Subscriptions


Additional Resources

If you have questions, issues, or need additional information, refer to:

 Resource       Link
CommunityDeveloper Community Forum


Version history
Last update:
‎Nov 16, 2022 03:54 PM
Updated by:
Labels (1)