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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Not able to execute ThingWorx Service through ThingWorx Subscription

Aditya1702
13-Aquamarine

Not able to execute ThingWorx Service through ThingWorx Subscription

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

1 ACCEPTED SOLUTION

Accepted Solutions
Rocko
17-Peridot
(To:Aditya1702)

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

View solution in original post

12 REPLIES 12

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

 

Aditya1702
13-Aquamarine
(To:Arun_C)

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
17-Peridot
(To:Aditya1702)

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

 

Aditya1702
13-Aquamarine
(To:Rocko)

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
17-Peridot
(To:Aditya1702)

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"

Aditya1702
13-Aquamarine
(To:Rocko)

Hi @Rocko 

 

Yes, I got why the error is coming & therefore I tried to add data the way it is shown in the document which is provided by you.

But in that document too after entering the data we have to execute the ThingWorx service by clicking on to the execute button on to the ThingWorx service to add that entry into the datatable.

 

I have attached the reference image for the same

 

 

Rocko
17-Peridot
(To:Aditya1702)

Your subscription will not work if the code you are calling throws an exception. Fix the exception first. I told you what to look for.

 

I did not send a link to a document called "Creating a Database in Thingworx" so I don't know why you are quoting this.

Aditya1702
13-Aquamarine
(To:Rocko)

Hi @Rocko 

 

Aim: To store records in a datatable from vuforia studio

 

You got what I want to achieve right, so can you please tell me the best approach that I should go with.

Whether I should use stream to store data or should I create a datatable to store the data.

I am new to this platform hence I am trying multiple ways to achieve it.

 

You can guide me with the best approach to store records with the timpstamp.

 

 

Thanks in Advance.

 

Regards,

Aditya Gupta

 

 

 

Aditya1702
13-Aquamarine
(To:Aditya1702)

Hi @Rocko ,

 

Can we store image in a datatable of ThingWorx?

Rocko
17-Peridot
(To:Aditya1702)

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

Aditya1702
13-Aquamarine
(To:Rocko)

Hi @Rocko,

 

Thank you so much for your help.

 

I am able to store the required data into ThingWorx datatable from Vuforia Studio.

Right now I am not facing any issues, I will let you know if any in future.

 

Also, if you can provide me with any  materials/links to explore about ThingWorx it would be of great help.

 

Thanks & Best Regards,

Aditya Gupta.

 

 

 

Rocko
17-Peridot
(To:Aditya1702)

If you go to https://community.ptc.com/t5/IoT-Tips/tkb-p/tkb_iottips there are lots of tutorials and on the right side you will find a reference to the Thingworx Learning Path which is a great resource to get started.

Top Tags