Skip to main content
1-Visitor
March 13, 2018
Question

Set Property Units field

  • March 13, 2018
  • 2 replies
  • 1931 views

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

5-Regular Member
March 14, 2018

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.

22-Sapphire I
March 14, 2018

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?