Not able to execute ThingWorx Service through ThingWorx Subscription
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
Thanks & Regards,
Arun C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @Arun_C
The output of my service is set to nothing as the service just adds data to the table.
Regards,
Aditya Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.