Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
I have a property for a Thing "WeatherRover" which has a property "Speed". While creating "Speed" property, i mentioned following BaseType info,
Base Type: Number
Units: km/hr
Min Value: 0
Max Value: 20
Now I want to use this Base Type info on the mashup i.e. Units, Min Value and Max Value. How to get this BaseType information provided for each property? I tried using "GetPropertyDefinition" Service, but it doesn't gives all the info needed.
I also tried with other services like GetPropertyDefinitions, GetPropertyValues, GetPropertyLogging but none of them giving me the information I am looking for. Any help around it would be appreciated.
Thanks,
Ketan
Hello, Ketan.
What results to you get returned from 'GetPropertyValues?' That would normally be my first thought here.
-- Craig A.
Hi Ketan,
There's no Out-Of-The-Box service to recover Units, Min and Max Values. You will have to build you own service which internally recovers it and builds an Infotable with the desired metadata.
Here you have a sample code to recover thouse Property aspectects:
var values = me.GetNamedProperties({ propertyNames: { "items": [ "myPropertyName"] } } );
var fieldAspects = values.dataShape.fields["myPropertyName"].aspects;
// -- List of available aspects:
fieldAspects.thingShape
fieldAspects.thingTemplate
fieldAspects.isReadOnly
fieldAspects.isPersistent
fieldAspects.isLogged
fieldAspects.units
fieldAspects.dataChangeType
fieldAspects.dataChangeThreshold
fieldAspects.defaultValue
fieldAspects.minimumValue
fieldAspects.maximumValue
fieldAspects.dataShape
values.dataShape.fields["myPropertyName"].category
values.dataShape.fields["myPropertyName"].description
Hope It helps.
var values = Things["MyThing"].GetNamedProperties({ propertyNames: { "items": [ "MyPropertyName"] } } );
var result1 ={};
var fieldAspects = values.dataShape.fields["MyPropertyName"].aspects;
// -- List of available aspects:
//var result = JSON.stringify(fieldAspects);
result1.myprop1= null
result1.myprop2 = undefined
result1.thingShape = fieldAspects.thingShape
result1.thingTemplate = fieldAspects.thingTemplate
result1.isReadOnly = fieldAspects.isReadOnly
result1.isPersistent = fieldAspects.isPersistent
result1.isLogged = fieldAspects.isLogged
result1.units = fieldAspects.units
result1.dataChangeType = fieldAspects.dataChangeType
result1.dataChangeThreshold = fieldAspects.dataChangeThreshold
result1.defaultValue = fieldAspects.defaultValue
result1.minimumValue = fieldAspects.minimumValue
result1.maximumValue = fieldAspects.maximumValue
result1.dataShape = fieldAspects.dataShape
result1.category = values.dataShape.fields[PropertyName].category
result1.description = values.dataShape.fields[PropertyName].description
var result = JSON.stringify(result1);
I am getting back this:
{
"minimumValue": 1,
"isReadOnly": false,
"dataChangeThreshold": 22,
"defaultValue": 17,
"isPersistent": true,
"myprop1": null,
"isLogged": true,
"dataChangeType": "VALUE",
"units": "Meter",
"maximumValue": 11,
"cacheTime": 44000
}
It seems other aspects are undefined and they won't appear in the result. As a test myprop2 doesn't appear in the result since it is undefined. category and description are not returned (btw i set them to some value)
Is your snippet valid? How to know what is available on aspects property? What Java class it corresponds to?
I think: com.thingworx.types.collections.AspectCollection
How can I convert this collection using .toJSON(string) (which is not available on this collection) so I can see what properties are available on it?
thanks,
Rad