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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Thing addProperty(...) doesn't work

rtaylor-3
1-Newbie

Thing addProperty(...) doesn't work

Let me preface this by "I know i must be doing something wrong".

Thing t = new Thing();

t.addProperty(new PropertyDefinition("myProperty", "myPropertyDescription", BaseTypes.Boolean));

InfoTable pd = t.GetPropertyDefinition("myProperty"); // unexpectedly returns null

This seems so basic and trivial. What am i doing wrong?

1 ACCEPTED SOLUTION

Accepted Solutions

Hmmmm....just decompiled the Thingworx Extension SDK 7.2.0 and it appears a lot of methods are just empty stubs.

Thing

@ThingworxExtensionApiMethod(since={6, 6})

  public ThingProperty addProperty(PropertyDefinition propertyDefinition)

    throws Exception

  {

    return null;

  }

RootEntity

  @ThingworxExtensionApiMethod(since={6, 6})

  @ThingworxServiceDefinition(isLocalOnly=true, name="GetPropertyDefinition", description="Get the current property definitions for this thing", category="Metadata")

  @ThingworxServiceResult(name="result", description="Property definition", baseType="INFOTABLE", aspects={"dataShape:PropertyDefinition"})

  public InfoTable GetPropertyDefinition(@ThingworxServiceParameter(name="name", description="Name", baseType="STRING") String name)

    throws Exception

  {

    return null;

  }

View solution in original post

5 REPLIES 5

You should restart the thing.

Doesn't work for me. Same behavior...still returns null.

Thing t = new Thing();

t.addProperty(new PropertyDefinition("myProperty", "myPropertyDescription", BaseTypes.Boolean));

t.RestartThing();

InfoTable pd = t.GetPropertyDefinition("myProperty"); // unexpectedly returns null

BTW, i'm using Thingworx Extension SDK 7.2.0

Hmmmm....just decompiled the Thingworx Extension SDK 7.2.0 and it appears a lot of methods are just empty stubs.

Thing

@ThingworxExtensionApiMethod(since={6, 6})

  public ThingProperty addProperty(PropertyDefinition propertyDefinition)

    throws Exception

  {

    return null;

  }

RootEntity

  @ThingworxExtensionApiMethod(since={6, 6})

  @ThingworxServiceDefinition(isLocalOnly=true, name="GetPropertyDefinition", description="Get the current property definitions for this thing", category="Metadata")

  @ThingworxServiceResult(name="result", description="Property definition", baseType="INFOTABLE", aspects={"dataShape:PropertyDefinition"})

  public InfoTable GetPropertyDefinition(@ThingworxServiceParameter(name="name", description="Name", baseType="STRING") String name)

    throws Exception

  {

    return null;

  }

Hi Robert,

You should be able to Add a property to a newly created thing, I do it from Server Side Javascript without issues.

First thing on your code that's strange it's how you create a Thing without giving it a name and a Parent thing Template, doing a quick search on support.ptc.com I found this article that shows you how to create a new Thing https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS243376

First step covered, how to create a thing, if you see that code, after creating it EnablesThing() and then it RestartThing(); that's important.

To Add a property I thing you should use AddPropertyDefinition(name,description,type,...) you can see reference code on: Digital Media Publisher

Best regards,

Carles.

Hi Carles,

I'm writing some JUnit tests. So i don't have Thingworx context running.

I'm testing a utility method which simply facilitates accessing a boolean property value and catches any exceptions.

I just need to populate a Thing (any Thing) with the appropriate property definition and subsequently a property value.

I'm using the Thingworx Extension SDK 7.2.0. As mentioned above, the methods i need are not implemented.

For now, i'm going to try and use EasyMock/PowerMock to mock up the method return values.

Top Tags