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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

How to update Infotable property using service in extension ?

Velkumar
19-Tanzanite

How to update Infotable property using service in extension ?

Hello all,

 

I'm trying to update Infotable property value using "UpdatePropertyValues" service. When I run the code, I'm getting error as "Unable To Convert From java.lang.String to INFOTABLE". Below is my code,

DataShapeDefinition updatepropertyShape = new new DataShapeDefinition();
updatepropertyShape.addFieldDefinition(new FieldDefinition("name",BaseTypes.STRING)); updatepropertyShape.addFieldDefinition(new FieldDefinition("time",BaseTypes.DATETIME)); updatepropertyShape.addFieldDefinition(new FieldDefinition("quality",BaseTypes.STRING)); updatepropertyShape.addFieldDefinition(new FieldDefinition("value",BaseTypes.STRING)); InfoTable updateproperty = new InfoTable(updatepropertyShape); Calendar currenttime = Calendar.getInstance(); JSONObject values = new JSONObject(); values.put("time", new DateTime(currenttime)); values.put("quality", "GOOD"); values.put("name", "MBT_CapacityOfMachine"); values.put("value", parsedValue); //ParsedValue is Infotable updateproperty.AddRow(values); thingName.UpdatePropertyValues(updateproperty);

I tried using "setPropertyValue" in service, I'm getting error as "com.thingworx.types.InfoTable cannot be cast to com.thingworx.types.primitives.IPrimitiveType"

 

thingName.setPropertyValue("Prope1", (IPrimitiveType<InfoTablePrimitive,InfoTable>) propertyValue);

 

Can any one help me to fix this issue ?

 

Regards,
VR

ACCEPTED SOLUTION

Accepted Solutions

I don't know exactly on how do to it with Java extension, but on your code I can see some incongruences:

  • you have a double new new on DataShapeDefinition creation.
  • you are setting value field on the JSON with an Infotable (parsedValue) but you add it to and Infotable that this field is defined a STRING field not an INFOTABLE field --> this may indicate your error.

 

View solution in original post

4 REPLIES 4

I don't know exactly on how do to it with Java extension, but on your code I can see some incongruences:

  • you have a double new new on DataShapeDefinition creation.
  • you are setting value field on the JSON with an Infotable (parsedValue) but you add it to and Infotable that this field is defined a STRING field not an INFOTABLE field --> this may indicate your error.

 

Velkumar
19-Tanzanite
(To:CarlesColl)

Hi @CarlesColl,

 

Thanks for your reply.

 

1. Double new is typo. It occurred while copying and pasting code in community.

2. When I convert infotable to String using "toString()" function it works fine.

 

Regards,

VR

Yes using toString you are converting the parsedInfotable to String again and your value it's of String and then it works as String but not as Infotable, what if you change the field definition for value to INFOTABLE ?

Velkumar
19-Tanzanite
(To:CarlesColl)

No, it working as INFOTABLE in extension. I just converted INFOTABLE to STRING and update my INFOTABLE property, it working fine.

Announcements


Top Tags