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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Cannot get ThingShape object which I want to modify programmatically

rad1
9-Granite

Cannot get ThingShape object which I want to modify programmatically

In the below script thingShape is undefined. I am using ThingWorx 8.1

Don't we have a way to retrieve a ThingShape and modify it or retrieve its property definitions programmatically once we created it with this code:

 

Resources["EntityServices"].CreateThingShape(params);

 

 

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

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


var thingShape = ThingShapes["MyThingShape"]

 

I would like to created ThingShapes properties as remote ones and give it Remote Prop Name.

 

The only way I could find if a ThingShape exists is by using this code:

        var params = {
            maxItems: undefined /* NUMBER */,
            nameMask: thingShape /* STRING */,
            type: "ThingShape" /* STRING */,
            tags: undefined /* TAGS */
        };

        // result: INFOTABLE dataShape: RootEntityList
        var matchingEntries = Resources["EntityServices"].GetEntityList(params);

... but this returns RootEntityList, wich is a read only object I cannot act on.

This article mentioned ThingShapes[ThingShapeName] as a way to retrieve the ThingShape but as I mentioned it doesn't work. 

How to change specific ThingShape propertydefinition

 

Also I noticed an error in Snippents for Entities filtered to ThingShape.

GetPropertyDefinitions snippet seems to be the same for both types pointing to DataShapes object holding both ThingShape and DataShape. Correct me please if I don't understand this properly.

 

Thanks,

Rad

 

 ThingShape snippet problem

 

4 REPLIES 4
amittal-3
13-Aquamarine
(To:rad1)

Hi Rad,

I think you can also get whether a particular ThingShape exists or not using the following piece of code - 

var params = {
	name: undefined /* STRING */,  //Put the name of your ThingShape
	type: "ThingShape" /* STRING */
};

// result: BOOLEAN
var result = Resources["SecurityServices"].EvaluateVisibilityPermission(params);

It will return true or false depending on the visibility and its existence. I think this inbuilt service is more appropriate for your use case as it will not only tell you if the Entity (ThingShape in this case) exists or not but also if it is allowed to be accessed, since you wish to modify it?

Thanks

Aditya

rad1
9-Granite
(To:amittal-3)

Aditya,

 

I want to be able to get a reference to ThingShape back so I can manipulate it.

 

amittal-3
13-Aquamarine
(To:rad1)

Hello Rad,

If you would like to modify the ThingShape (say if you want to add a new property to it), you can do the following - 

//Step 1: Check if the ThingShape exists or not

//Step 2: If yes, the add property to that Shape using a service; which can be done as follows -

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

ThingShapes["MyThingShape"].AddPropertyDefinition(params);

I hope this is what you want to do.

Regards

Aditya

Another way to know if a ThingShape exists it's this:

 

if (ThingShapes["myThingShape"]==null) --> Doesn't exists.

Top Tags