Skip to main content
1-Visitor
July 10, 2018
Question

Fetch Datashape from a infotable as a string

  • July 10, 2018
  • 4 replies
  • 3031 views

Hi Team,

 

I have a infotable that contains a list of info tables as it fields.

I am trying to fetch datashape of the infotable present in each field.

But it always returns result as com.thingworx.metadata.DataShapeDefinition@e69545d5

Using the above result as params  I am not able create a infotable .

 

Can someone help with syntax with which the above result may be used to fetch exact name of datashape used in infotable as string 

4 replies

5-Regular Member
July 10, 2018

Hi @cmartis would it be possible for you to share how you are attempting to extract the name of the datashape? 

1-Visitor
July 12, 2018

Use the following code to know the fields of the corresponding datashapes:

 

 

 var fields ;
 if ((infotable.dataShape==null)||(infotable.dataShape==undefined)) {
 fields = infotable.ToJSON().dataShape.fieldDefinitions;
 } else {
 fields = infotable.dataShape.fields;
 }

 

5-Regular Member
July 13, 2018

Hey @cmartis,

 

It is not possible to derive the DataShape name from an InfoTable. The underlying structure of an InfoTable, which can be viewed in JSON, is this:

 

{ 
 "dataShape":{ 
 "fieldDefinitions":{ 
 "val1":{ 
 "name":"val1",
 "description":"",
 "baseType":"NUMBER",
 "ordinal":1,
 "aspects":{ 

 }
 },
 "val2":{ 
 "name":"val2",
 "description":"",
 "baseType":"NUMBER",
 "ordinal":2,
 "aspects":{ 

 }
 }
 }
 },
 "rows":[ 
 { 
 "val1":10,
 "val2":12
 }
 ]
}

Note that the object contains the fieldDefinitions, with all of their types, but not the Entity name of the DataShape the InfoTable was created from. 

 

Why do you need to find the Data Shape name? If you just need to create an InfoTable of the same DataShape, you can create it in JSON -- using the dataShape JSON from the InfoTable -- with the above format and use the FromJSON() snippet. If you need to iterate through the fields, you can use @CarlesColl's example in this thread.

cmartis1-VisitorAuthor
1-Visitor
July 16, 2018

Hi all,

 

I could fetch the datashape of the info table that resides with Info table's aspects property