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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Property values are repeating while using QueryPropertyHistory Service in ThingWorx

Aditya1702
15-Moonstone

Property values are repeating while using QueryPropertyHistory Service in ThingWorx

Hello Everyone

Good Evening,

 

I am facing problem in logging properties there are some values which are repeating after I carry out the experience multiple times.

PFA attached image in which arrows are shown on the readings which are repeating when I consume the AR experience on my Ipad on view app for multiple times.

 

I just want to log the properties which are entered by the user on vuforia view app.

Below is the code I am using to write properties from Vuforia Studio to Thingworx:

I have written 2 services for pass & fail

 

Vuforia Studio JS Code:

 

$scope.SetStartStagePass = function (width) {
 
var TWXmodelID = 'Camera_UserStats_DT';
    var serviceName = 'GetSummary';
    var d = new Date();
    var parameters = { 'Emp' : $scope.app.params.empID, 'PartNumberInput' : $scope.app.params.partNo, 'Stage' : 'Step-' + j, 'StepValue' : 'Pass', 'DefectInput' : 'NA', 
                      'StepImageInput' :  $scope.view.wdg['camera'].image};
    
    //console.log("Starting UPLOAD using image size " + width);
    twx.app.fn.triggerDataService('Camera_UserStats_DT', serviceName, parameters);
 
}
 
$scope.SetStartStageFail = function (width) {
 
var TWXmodelID = 'Camera_UserStats_DT';
    var serviceName = 'GetSummary';
    var d = new Date();
    var parameters = { 'Emp' : $scope.app.params.empID, 'PartNumberInput' : $scope.app.params.partNo, 'Stage' : 'Step-' + j, 'StepValue' : 'Fail', 'DefectInput' : $scope.app.params.defect, 
                      'StepImageInput' : $scope.view.wdg['camera'].image}; 
    
    //console.log("Starting UPLOAD using image size " + width);
    twx.app.fn.triggerDataService('Camera_UserStats_DT', serviceName, parameters);
 
}

 

Thanks in Advance.

ACCEPTED SOLUTION

Accepted Solutions

Hi @Aditya1702 

 

Instead of logging data into the ValueStream. You can use Stream or DataTable (if it is low-frequency data) to store data in Thingworx which will avoid multiple entries.

 

Please refer here for DataTable services -Data Table Services (ptc.com)

About stream -Streams (ptc.com)

 

/VR

 

 

View solution in original post

30 REPLIES 30

Did you forget an attachment?

Aditya1702
15-Moonstone
(To:Rocko)

Hi,

Yes I forgot, I am attaching it now.

My purpose is I want to enter records row by row into an infotable.

eg, I have these field definitions in datashape: ID, Name, Status, TimeStamp - I want to enter records for these columns,

Record1: 1, Name1, Pass, 27/03/2024

Record2: 2, Name2, Fail, 27/03/2024

Record3: 3, Name3, Pass, 27/03/2024

 

 

Thanks in Advance.

 

 

Hi @Aditya1702 

 

How are logging values in Thingworx ?

 

Are you using Value Stream to do it with log enabled properties ?

 

/VR

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar ,

Good Morning,

Yes I am using value stream to log values but I am not sure whether I will achieve the output what I want using value streams.

 

Thanks in Advance.

 

Regards,

Aditya Gupta

Hi @Aditya1702 

 

Could you please explain your use case. From where you are getting data and why you have used Value Stream to store data.

 

Usually, value streams create an entry for each property change. For example:  if you have 3 logged properties when all 3 properties changed, the value stream inserts 3 rows (each row for each property change). That is the reason for the duplicated value.

Velkumar_0-1711606442750.png

There are multiple ways to overcome this. To overcome this, you can store data in Stream, DataTable or External DB.

 

/VR

 

Aditya1702
15-Moonstone
(To:Velkumar)

Hi,

 

Actually Ill explain through an example:

Suppose there are 3 users, So when user1 consumes the experience he records different values for prop1, prop2 & prop3

similarly, user2 records different values for prop1, prop2 & prop3

and user3 records different values for prop1, prop2 & prop3

 

So I want to store these values as datatable in thingworx for future reference.

 

 

Hi @Aditya1702 

 

Instead of logging data into the ValueStream. You can use Stream or DataTable (if it is low-frequency data) to store data in Thingworx which will avoid multiple entries.

 

Please refer here for DataTable services -Data Table Services (ptc.com)

About stream -Streams (ptc.com)

 

/VR

 

 

Aditya1702
15-Moonstone
(To:Velkumar)

Hi,

Can you guide me step by step on how to achieve it?

It would be of great help.

I am taking Vuforia View user input for property values.

 

Thanks & Best Regards,

Aditya Gupta 

Hi @Aditya1702 

 

Considering our sample 

 

1. Create a Datashape with 3 properties 

Velkumar_0-1711626162155.png

 

2. Create Stream and select datashape created in Step 1

Velkumar_1-1711626383283.png

 

3. Create a service to insert data into the stream

Velkumar_2-1711626806196.png

// Values: INFOTABLE dataShape: ""
let Values = Things["STREAM_NAME"].CreateValues();
Values.field1 = prop1;
Values.field2 = prop2;
Values.field3 = prop3;
Things["STREAM_NAME"].AddStreamEntry({
  sourceType: undefined /* STRING */,
  values: Values /* INFOTABLE */,
  location: undefined /* LOCATION */,
  source: undefined /* STRING */,
  timestamp: undefined /* DATETIME */,
  tags: undefined /* TAGS */,
});

 

4. Call this service in Vuforia Studio and bind inputs

 

/VR

 

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar ,

 

Where should the service be written inside the stream or inside a new datatable thing?

Also, what should be kept in output of service?

Hi @Aditya1702 

 

Create service in Stream Thing or any other entity based on your use case

 

Based on your requirement, if you want to show some status set as STRING or NOTHING

 

/VR

Aditya1702
15-Moonstone
(To:Velkumar)

Hi, @Velkumar ,

 

I want the output in a table form so, can I keep the output of the service as an Infotable with the corresponding datashape ?

 

Hi @Aditya1702 

 

Yeah please set it as InfoTable and select datashape

 

Also update your script :

// Values: INFOTABLE dataShape: ""
let Values = Things["STREAMNAME"].CreateValues();
Values.field1 = prop1;
Values.field2 = prop2;
Values.field3 = prop3;
Things["STREAMNAME"].AddStreamEntry({
  sourceType: undefined /* STRING */,
  values: Values /* INFOTABLE */,
  location: undefined /* LOCATION */,
  source: undefined /* STRING */,
  timestamp: undefined /* DATETIME */,
  tags: undefined /* TAGS */,
});
 
// result: INFOTABLE dataShape: ""
let result = Things["STREAMNAME"].QueryStreamEntriesWithData({
  oldestFirst: undefined /* BOOLEAN */,
  maxItems: undefined /* NUMBER {"defaultValue":500} */,
  sourceTags: undefined /* TAGS */,
  endDate: undefined /* DATETIME */,
  query: undefined /* QUERY */,
  source: undefined /* STRING */,
  startDate: undefined /* DATETIME */,
  tags: undefined /* TAGS */
});

 

/VR

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar ,

Good Morning,

 

I have written the service provided by you in a datatable thing but, its throwing an error as:

 

Error executing service InspectionStep. Message :: Unable To Convert From java.lang.String to NUMBER - See Script Error Log for more details.

 

I have attached the images of the same.

 

Thanks & Best Regards,

Aditya Gupta.

 

 

Hi @Aditya1702 

 

The issue is you are trying to convert String to Number. Check you inputs for Number datatype wether you are passing any string to it

 

/VR

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar ,

 

I checked it the inputs are proper also, you can see in the screenshots attached (Screenshot(1097).png the inputs from Vuforia View app are reflecting in the properties of ThingWorx (ThingWorx 9.4.1)

 

You can see in the Screenshot(1098).png it is throwing error when I execute the service but when I manually give the inputs in ThingWorx & then execute the service it is showing some output which you can see in Screenshot(1099).png

Hi @Aditya1702 

 

I don't see any input in your manual execution. Please enter values in your service input and execute it 

 

/VR

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar ,

I have mentioned the input in service which are coming from Vuforia View app on Ipad. 

I have attached image for reference so that yo can see there is no problem on getting input from Ipad.

On execution of service it is still throwing the same error:

ERROR:

Error executing service InspectionStep. Message :: Unable To Convert From java.lang.String to NUMBER - See Script Error Log for more details.

 

I don't know where am I going wrong.

 

Thanks & Best Regards,

Aditya Gupta

 

 

Hi @Aditya1702 

 

Please fill circled value in Thingworx Composer and execute the service. To check whether it throwing any error

 

Velkumar_0-1711714591981.png

 

/VR

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar 

 

No after entering values in the area shown by you it does not throws any error.

I've attached the screenshot of the same below.

 

 

Hi @Aditya1702 

 

It means the service working properly. You have to pass proper input from Vuforia Studio to make it work

 

/VR

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar ,

 

Below is the code I have written in Vuforia Studio to take input,

Code:

 

$scope.SetStartStagePass = function (width) {
 
var TWXmodelID = 'Inspection-DT';
    var serviceName = 'InspectionStep';
    var d = new Date();
    var parameters = { 'EmpIDInput' : $scope.app.params.empID, 'PartNumberInput' : $scope.app.params.partNo, 'StepNumberInput' : 'Step-' + j, 'StepStatusInput' : 'Pass', 'StepImageInput' : $scope.view.wdg['camera'].image, 'StepDefectInput' :  $scope.app.params.defect};
    
    //console.log("Starting UPLOAD using image size " + width);
 
    twx.app.fn.triggerDataService('Inspection-DT', serviceName, parameters);
 
}
 
Also, I had attached reference image of properties which took input from Vuforia Studio that means there could be another problem since the inputs from Vuforia View App are reflecting in properties of ThingWorx.
 
 
Thanks & Best Regards,
Aditya Gupta

Hi @Aditya1702 

 

Log parameters in the console and debug it. Sorry it is really difficult for me to debug without Vuforia Studio

 

/VR

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar ,

Good Morning,

 

My concern was, if the ThingWorx properties are reflecting input from Vuforia Studio then why isn't the ThingWorx Service which

we created not working.

 

Any suggestion you can provide?

 

Regards,

Aditya Gupta

 

Hi @Velkumar ,

 

I am using stream to store values. 

It's working but the problem is after every single record I need to manually press the execute button in ThingWorx service to store the data into Stream.

 

Eg. I capture record1 then need to manually press execute button of ThingWorx InspectionAddData service.

Capture record2 again manually press the execute button in ThingWorx InspectionAddData service.

Capture record3 again manually press the execute button in ThingWorx InspectionAddData service.

 

Now the problem is, how can I trigger execute button of ThingWorx InspectionAddData Service from Vuforia Studio?

 

Thanks & Best Regards,

Aditya Gupta.

 

 

As the duplicate row has a different timestamp this suggests that either there are other columns in the value stream not shown in the screenshot, and/or that the service setting the values is actually called twice. The timestamps in the screenshot are very close to each other (21ms).

In any posting, please also include per default which TWX version you are running.

H_1234
11-Garnet
(To:Rocko)

Hi Aditya1702,

QueryPropertyHistory service had a some smart logging capability. PF below link https://www.ptc.com/en/support/article/cs226000  and try to understand the possibility before using it.
it will help to get in detail about the queryPropertyHistory service.



Best Regards,
Hareef.Pinjari

thanks for sharing

Hello @Aditya1702,

 

It looks like you have some responses from some community members. If any of these replies helped you solve your question please mark the appropriate reply as the Accepted Solution. 

Of course, if you have more to share on your issue, please let the Community know so other community members can continue to help you.

Thanks,
Community Moderation Team.

Announcements


Top Tags