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 PTC Community Badges. Engage with PTC and see how many you can earn! X

JS Service to provide agent's VirtualThing dynamic property initialization based on ThingTemplate

rad1
9-Granite

JS Service to provide agent's VirtualThing dynamic property initialization based on ThingTemplate

DeflectorProperty.jpg

 

I have a template with field like "Deflector" of NUMERIC type (and other properties not show in above image).

I would like to create a JavaScript service that will based on template name return a collection of JSON objects

containing all property information that can be seen in the image. 

I want to build agent with a VirtualThing implementation that will be based on this JSON configuration that can be retrieved from the TW JS service.

In addition I would like to add "custom aspects" like: System, Group and Model that can be associated with each property (Can I use some kind of linked DataTable that I need to maintain using a custom mashup where I would show property names in one column, hide ThingTemplate name (which will point to TT name) and add DataShape columns: System, Group and Model). Can this be achieved differently?

 

[{....}, {....},{
"Name": "Deflector",
"Description": "Deflector",
"Category": "Overview",
"BaseType": "NUMBER",
"Units": "meter",
"MinValue": "0",
"MaxValue": "120",
"HasDefaultValue": true,
"DefaultValue": "0",
"Persistent": false,
"ReadOnly": false,
"Logged": true,
"DataChangeType": "VALUE",
"ChangeThreshold": "2",
"CacheOptions": "",
"PushType": "VALUE",
"PushThreshold": "1",
"System": "MonoLaser",   >>> Desired as extra aspect
"Group": "Optics",            >>> Desired as extra aspect
"Model": "ML4000",          >>> Desired as extra aspect
},{....}

]

 

I tried these service calls: GetRemotePropertyBinding, GetNamedProperties, GetPropertyValues, but 

I don't get all information needed by the agent to build VirtualThing's properties in the constructor of inherited class anding with initialize() VirtualThing call.

 

I would prefer to base this service on the Template name since I would know what template VirtualThing will be using on the server. I also have ThingShapes which will be implemented by some ThingTemplates.

 

Thank you,

Rad

1 ACCEPTED SOLUTION
5 REPLIES 5
PaiChung
22-Sapphire I
(To:rad1)

The retrieval of this configuration should come back as an InfoTable (like get PropertyDefinition or something similar or GetPropertyBinding ... )

I am not sure if you have the agent set up to use InfoTables as is, else potentially the ToJSON service can work.

rad1
9-Granite
(To:PaiChung)

Based on these links:

http://support.ptc.com/help/thingworx_hc/thingworx_8_hc/index.html#page/ThingWorx%2FHelp%2FComposer%2FThings%2FThingProperties%2FProgrammaticallyAddingPropertiestoThings.html%23

https://community.ptc.com/t5/ThingWorx-Developers/Set-Property-Units-field/td-p/539958

 

We can create remote-bound property on a thing template using AddPropertyDefinition  service.

I cannot see how to programmatically set these aspects:

Cache Option

Cache Interval

When Disconnected and 

Timeout settings.

 

So is there any way to get/set these 4 properties. I thing I will be able to get other property aspects.

Thanks,

Rad

 

 

rad1
9-Granite
(To:PaiChung)

This is what I came up with. 

If I used GetMetadataAsJSON and GetRemotePropertyBinding I can get majority of property metadata except:

Units
Min Value
Max Value
Has Default Value
Default Value and 

When Disconnected

 

Any way this can be retrieved somehow?

PropertyDefinitionRetrieval.jpg

rad1
9-Granite
(To:PaiChung)

This is something I was looking for.

Now remaining issue is how to enrich this property metadata with some custom things: like mnemonic, scale etc.

Will a linked DataTable (that will have a primary key: ThingTemplate name, Property name with additional columns: mnemonic, scale...) provide missing metadata where I would combine results of the accepted solution code and joined values from this DataTable.

 

Thanks,

Rad

Top Tags