Descriptive Analytics > Implementing Service Calls
Implementing Service Calls
Chaining Calls
In the Descriptive Analytics microservers, the output of one service call often becomes the input for the next. A common way to execute these service calls is to chain them together in your code. The ThingWorx Composer interface offers a few ways to chain service calls together on a Thing where you are attaching one of the Descriptive Analytics Data Shapes:
Thing Service – You can write a javascript service on the Thing. For more information, see Thing Services in the ThingWorx Foundation Help Center.
Event Subscription – You can create a subscription based on an event on the Thing. For more information, see Thing Subscriptions.
Mashup – In the Mashup Builder, you can bind a service to the Thing. For more information, see Mashup Builder.
Sample Code
The sample of code below includes two service calls chained together. The first service call queries a Value Stream for data and stores the resulting data in a timedValues variable. The next service call uses the timedValues data as input to a service call that calculates five-number results.
Each service call can return only one result, whether that result is a number or an infotable. Also, as a function of ThingWorx service calls, output must always be assigned the property name: result.
The following code sample could be used in a Thing service or as part of an event subscription:
// result: INFOTABLE dataShape: "AnalyticsTimedValue"
var timedValues = me.QueryTimedValuesForProperty({
maxItems: undefined /* NUMBER */,
propertyName: "temperatureData" /* STRING */,
startTime: undefined /* DATETIME */,
endTime: undefined /* DATETIME */
});

// result: INFOTABLE dataShape: "AnalyticsFiveNumberSummaryResult"
var result = me.CalculateFiveNumberPropertyValues({
timedValues: timedValues /* INFOTABLE */
});
Was this helpful?