Skip to main content
16-Pearl
April 2, 2024
Solved

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

Best answer by Rocko

Yes. The datashape would have property of base type IMAGE then. Keep in mind DataTables are not to be used for more than 100k rows.

 

Also consider this and this

2 replies

16-Pearl
April 2, 2024

Hi @Aditya1702 ,

 

Can you please check the service output type is "Infotable"? If no results need to print out of service then make it with "Nothing",

Also, Try to execute the service manually to check the error.

Arun_C_0-1712068595448.png

Thanks & Regards,

Arun C

 

16-Pearl
April 3, 2024

Hi @Arun_C 

 

The output of my service is set to nothing as the service just adds data to the table.

 

Regards,

Aditya Gupta

Rocko
19-Tanzanite
April 2, 2024

Things["Inspection-Stream"].CreateValues(); will create an Infotable.

Your subsequent code is not how you add a row to an infotable.

You need to create an object, set the property values on the object, and then call AddRow with the object on the infotable.

Discussed here and here

 

16-Pearl
April 3, 2024

Hi @Rocko 

 

I went through the above link provided by you but in that link to we have to manually execute the ThingWorx service

to add data to the infotable.

 

 

Regards,

Aditya Gupta.

Rocko
19-Tanzanite
April 3, 2024

What does this have to do with manual execution?

You posted code saying it gives you an exception and I gave you an explanation why.

The document in the second link even has chapter literally called "Adding an object based on a DataShape to a Stream"