Not able to execute ThingWorx Service through ThingWorx Subscription
- April 2, 2024
- 2 replies
- 4459 views
Hello,
I want to store data into ThingWorx Stream (Inspection-Stream).
I have written a service in ThingWorx Datatable (Inspection-DT) to add data into stream
Code:
try {
// Your whole code here
// tags:TAGS
let tags = new Array();
// timestamp:DATETIME
let timestamp = new Date();
// values:INFOTABLE(Datashape:Inspection-DS)
let values = Things["Inspection-Stream"].CreateValues();
values.PartNumber = me.PartNumberProp; //NUMBER
values.StepNumber = me.StepNumberProp; //STRING
values.StepDefect = me.StepDefectProp; //STRING
//values.GUID = undefined; //GUID
values.StepImage = me.StepImageProp; //IMAGE
values.StepStatus = me.StepStatusProp; //STRING
values.EmpID = me.EmpIDProp; //NUMBER
values.DateTime = Date.now(); //DATETIME
// location:LOCATION
let location = {
latitude: 0,
longitude: 0,
elevation: 0,
units: "WGS84"
};
let params = {
tags: tags,
timestamp: timestamp,
source: me.name,
values: values,
location: location
};
// AddStreamEntry(tags:TAGS, timestamp:DATETIME, source:STRING("me.name"), values:INFOTABLE(Inspection-DS), location:LOCATION):NOTHING
Things["Inspection-Stream"].AddStreamEntry(params);
} catch(err) {
logger.error(err.message + " in line " + err.lineNumber);
}
I want to execute the above service through a subscription which is triggered whenever a property (DateTime) changes below is the service (AddData) written in Subscription
Code:
if(eventData.newValue.value){
me.InspectionAddData();
logger.warn('Successful'+eventData.newValue.value);
}
The output is giving an error, I have attached the error file.
Please help me out.
Thanks in Advance.
Regards,
Aditya Gupta

