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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

How to use UpdatePropertyValues Service in ThingWorx

No ratings

Let us consider that we have 2 properties Property1 and Property2 in Thing Thing1 which we want to update using UpdatePropertyValues service.

  1. In our service we will use a system defined DataShape NamedVTQ which has following field definitions:
  2. In Thing1 create a custom service like following:
    • var params1 = {

           infoTableName : "InfoTable",

           dataShapeName : "NamedVTQ"

      };

      // CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(NamedVTQ)

      var InputInfoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params1);

      var now = new Date();

      // Thing1 entry object

      var newEntry = new Object();

      newEntry.time = now; // DATETIME - isPrimaryKey = true

      newEntry.quality = undefined; // STRING

      newEntry.name = "Property1"; // STRING

      newEntry.value = "Value1"; // STRING

      InputInfoTable.AddRow(newEntry);

      newEntry.name = "Property2"; // STRING

      newEntry.value = "Value2"; // STRING

      InputInfoTable.AddRow(newEntry);

      var params2 = {

           values: InputInfoTable /* INFOTABLE */

      };

      me.UpdatePropertyValues(params2);

Comments

This DataShape exists in ThingWorx as "NamedVTQ".

Another way to do this without DataShape NamedVTQ: UpdatePropertyValues service

Thank you for the suggestion Quang.

Did you guys try to do the same with Java extension sdk?

When I code with:

  DataShape ds= (DataShape) EntityUtilities.findEntity("NamedVTQ", ThingworxRelationshipTypes.DataShape);

  InfoTable valueStreamInfoTable = ds.CreateValues();
  DateTime date = new DateTime();
  Long dateLong = date.getMillis();
  ValueCollection values = new ValueCollection();
  values.put("name", new StringPrimitive("prop1"));
  values.put("time", new DatetimePrimitive(dateLong));
  values.put("value", new StringPrimitive("hello1"));
  values.put("quality", new StringPrimitive("GOOD"));
  valueStreamInfoTable.addRow(values);
  values.put("name", new StringPrimitive("prop2"));
  values.put("time", new DatetimePrimitive(dateLong));
  values.put("value", new StringPrimitive("hello2"));
  values.put("quality", new StringPrimitive("GOOD"));
  valueStreamInfoTable.addRow(values);

  Thing myThing= (Thing) EntityUtilities.findEntity("MyThing", ThingworxRelationshipTypes.Thing);
  myThing.UpdatePropertyValues(valueStreamInfoTable);

And import the Extension onto ThingWorx and execute this service, only the last property will be updated(prop2 in my case).

Not sure if it's a bug or improper coding.

Br,

Anna

Hi Anna An  PUT puts a file or resource at a specific URI, and exactly at that URI. If there's already a file or resource at that URI, PUT replaces that file or resource.

If the Request-URI refers to an already existing resource (your secoond PUT req ), the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server, and thats why you only the data send by last req. That's by design.

Hi Ravi,

I agree what you pointed out is the root cause.

So whats your suggestion to call UpdatePropertyValues from Java Extension sdk? How update mul-ti properties all in one?

To tune this , you will need to understand the Aspect of the property on TWX platform.

There are several aspect and I am writing about few important one which can help you play around with this.

You need to look for dataChangeType — This field acts as the default value for the data change

type field of the property when it is added to the RemoteThing on the Platform.

The data change type describes how the ThingWorx server responds when the value in the RemoteThing on the server changes.

Subscriptions to these value changes can be created on the server.

If nothing needs to react to the property change, it is recommended that this value be set to NEVER. The possible values are listed and briefly described here:

Value Description

ALWAYS Always notify of the value change even if the same value comes in multiple times in a row

VALUE Notify only if the value changes

ON For BOOLEAN types, notify only if the value is true.

OFF For BOOLEAN types notify only if the value is false.

NEVER The server should do nothing based on the value change.

cacheTime — Tells the ThingWorx server how to behave when reading a

remote property. This parameter can take the following values:

○ -1 — Indicates that the VirtualThing always sends its value, and the

server should never request it from the remote application. The value

returned always comes from the in-memory cache of the server. Use this

value for properties that are configured to be pushed to the server.

○ 0 — Indicates that every time the server uses the value, it should request it

from the VirtualThing.

○ Any other positive value — Indicates that the server should cache the

value for that many seconds and then retrieve it from the VirtualThing

only after that time expires. This setting is important for properties that

may be accessed frequently by many users. For example, if 100 users

attempt to access a property value within a 10 second period, you may

want to set this value to 30 seconds. That would ensure that only a single

request for the property is sent to the edge every 30 seconds. However, the

value returned by the platform could be out of date by up to 30 seconds.

This setting is important for properties that may be frequently accessed by

many users. For example, if 100 users attempt to access a property value

within a 10 second period, you may want to set this value to 30 seconds.

That setting would ensure that only a single request for the property is sent

to the edge every 30 seconds. However, the value returned by the Platform

could be out of date by up to 30 seconds

pushType — Informs the server how the VirtualThing pushes its values to it.

The possible values are as follows:

Push Type Description

ALWAYS The VirtualThing sends updates even if the value

has not changed. it is common to use a cacheTime

setting of -1 in this case.

NEVER The VirtualThing never sends the value. It is

common to use a cacheTime setting of 0 or greater in

this case.

VALUE The VirtualThing sends updates only when the

value changes. It is common to use a cacheTime

setting of -1 in this case.

These evaluations are performed whenever the

updateSubscribedProperties() method of the VirtualThing. is

called to determine which properties to push to the server.

• defaultValue — The default value is the value that the ThingWorx server

uses when the RemoteThing connected to the VirtualThing first starts up and

has not had an update from the VirtualThing. The value is different based on

the type for each parameter.

• isFolded — Determines how property values are stored and pushed to the

Platform. If a property uses isFolded, only the last value set is pushed to

the Platform when updateSubscribedProperties is called. If

isFolded is FALSE, all property updates, along with a timestamp, are

queued and sent to the platform. The default value is TRUE.

You can go through SDK docs in details , and further you can POST values as well.

Hi Ravi,

Thank you very much for the detailed explanation.

I have checked the Java SDK docs before and I know the basic settings like pushType,  DataChange type,etc.

We could update all the property values automatically via Java SDK.

But I asked this question here is regarding how to manually call service "UpdatePropertyValues" from Java Extension sdk(not Java SDK :)?

This is based on some special use cases.

Many thanks,

Br,

Anna

"regarding how to manually call service "UpdatePropertyValues"  , you are already doing it .  However you need to use POST method rather than PUT . You missed my last line from long description.

Further , you also need to check if POST call is possible for this rest service or not . I believe it should be .

Version history
Last update:
‎Apr 12, 2017 12:56 AM
Updated by:
Labels (1)
Tags (1)