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

DataShape : Nuances, Tips & Tricks

No ratings

DataShape

Simply put, it represents the data in your model giving your application an in-built sense on how to represent the data in different scenarios. DataShape is defined with set of field definitions and related metadata e.g. DataType. DataShapes are must have (except for ValueStream) when creating entities that deal with data storage i.e. DataTable & Stream. For more detail on  DataShapes and the DataTypes see DataShapes in ThingWorx Help Center

 

Note: See ThingShape : Nuances, Tips & Tricks  for ThingShape vs DataShape

 

Ways to create DataShape

 

Via the ThingWorx Composer

  1. Navigate to ThingWorx Composer click on New > DataShape
  2. Provide a unique name to the DataShape entity
  3. imageDataShape creation in ThingWorx Composer
  4. Navigate to the Field Definition and add required Field Definition
  5. imageDefining Field for the DataShape

Via a custom service in ThingWorx

  1. Navigate to an entity under which the service is to be created, e.g. Thing
  2. Switch to Services section for the Thing and click Add to create new service
  3. OOTB available service CreateDataShape can be used from the Resources > EntityService
// snippet creating the infotable with the 

var params = {
    infoTableName : "InfoTable",
    dataShapeName : "DemoDataShape"
};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(DemoDataShape)
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);


// snippet creating the DataShape using the Infotable queried above which returns the field and the metadata on those fields
// DSName used below is created as the 

Resources["EntityServices"].CreateDataShape({
	name: DSName /* STRING */,
	description: "Custom created DataShape" /* STRING */,
	fields: result /* INFOTABLE */, 
	tags: undefined /* TAGS */
});

Here's how it'd appear in the Service editor :

 

imageDataShape creation with JavaScript service in ThingWorx

Via the ThingWorx Extension SDK

 

Following example snippet shows the creation and usage of the DataShape while creating custom extension with the Extension SDK 

 

@ThingworxConfigurationTableDefinitions(tables = {
		@ThingworxConfigurationTableDefinition(name = "ConfigTableExample1", description = "Example 1 config table", isMultiRow = false, dataShape = @ThingworxDataShapeDefinition(fields = {
				@ThingworxFieldDefinition(name = "field1", description = "", baseType = "STRING"),
				@ThingworxFieldDefinition(name = "field2", description = "", baseType = "NUMBER") })) })

Note: Refer to the ThingShape : Nuances, Tips & Tricks for Tips & Tricks

 

Other related reads

Version history
Last update:
‎Mar 09, 2018 09:14 AM
Updated by:
Labels (1)
Tags (1)