Skip to main content
1-Visitor
Sep 30, 2016 10:38 PM UTC
Solved

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?

rtaylor-3Answer
1-Visitor
Oct 1, 2016 12:00 PM UTC

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;

  }

5 replies

1-Visitor
Oct 1, 2016 5:55 AM UTC

You should restart the thing.

Translate
rtaylor-31-VisitorAuthor
1-Visitor
Oct 1, 2016 11:42 AM UTC

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

Translate
rtaylor-31-VisitorAuthorAnswer
1-Visitor
Oct 1, 2016 12:00 PM UTC

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;

  }

Translate
1-Visitor
Oct 1, 2016 2:22 PM UTC

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.

Translate
rtaylor-31-VisitorAuthor
1-Visitor
Oct 1, 2016 3:01 PM UTC

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.

Translate