Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
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?
Solved! Go to Solution.
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;
}
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.