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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

How to fetch BaseType information of property runtime?

kmagdum
14-Alexandrite

How to fetch BaseType information of property runtime?

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.

1_Property_Details.png

2_Mashup_Service.png

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

3 REPLIES 3
CRArko
17-Peridot
(To:kmagdum)

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.

rad1
12-Amethyst
(To:CarlesColl)

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

Announcements


Top Tags