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

Set Property Units field

rengineeringand
4-Participant

Set Property Units field

Hi all,

 

I'm struggling here trying to find a solution:

 

I need to set the value of Units programmatically while creating a new ThingShape, so far I haven't found a way to set it. 

Is there a way to do this?

 

Capturar.PNGThank you.

2 REPLIES 2

Hi @rengineeringand what i could quickly check is that you can test if this helps in your use case

 

var params = {
	defaultValue: undefined /* STRING */,
	remoteBindingAspects: undefined /* JSON */,
	description: undefined /* STRING */,
	readOnly: undefined /* BOOLEAN */,
	type: undefined /* BASETYPENAME */,
	remote: undefined /* BOOLEAN */,
	remotePropertyName: undefined /* STRING */,
	timeout: undefined /* INTEGER */,
	pushType: undefined /* STRING */,
	dataChangeThreshold: undefined /* NUMBER */,
	logged: undefined /* BOOLEAN */,
	name: undefined /* STRING */,
	pushThreshold: undefined /* NUMBER */,
	dataChangeType: undefined /* STRING */,
	category: undefined /* STRING */,
	persistent: undefined /* BOOLEAN */,
	dataShape: undefined /* DATASHAPENAME */
};

// no return
ThingShapes["TestThingShape"].AddPropertyDefinition(params);

Note here TestThingShape is just the name of the ThingShape I am creating like this

 

var params = {
	name: "TestThingShape" /* STRING */,
	description: "created programatically" /* STRING */,
	tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateThingShape(params);

 

Additionally, via the extension SDK this could be done like so :

 

		@ThingworxPropertyDefinition(name = "DemoTest", description = "", category = "", baseType = "NUMBER", isLocalOnly = false, aspects = {
				"minimumValue:10", "defaultValue:10", "dataChangeType:VALUE", "units:cm", "maximumValue:100" }) })

The values you are trying to set belong to the Class Aspects see JavaDocs

 

Hope this helps.

Please do note that at this time, the Units field is just metadata. it doesn't drive conversion of values.

They are also as you can see somewhat difficult to set and retrieve so they tend to not be exposed in the UI.

What is your use case for filling in the units? who will be seeing this information and using it?

Top Tags