Skip to main content
1-Visitor
April 10, 2019
Solved

How to Create Data shape Through Service in Thingworx

  • April 10, 2019
  • 1 reply
  • 4847 views

Hi Everyone,

 

I like to Create Datashape through TWX service with multiple number of Fields.

I found the Snippet in Thingworx its like. 

 

var params = {
name: undefined /* STRING */,
description: undefined /* STRING */,
fields: undefined /* INFOTABLE */,
tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateDataShape(params);

 

but i don't know How to give fields in the above snippet.

 

if anybody Know any solution  regarding this,Kindly share it  ASAP.

 

Thanks & Regards 

Sugumar R

Best answer by CarlesColl

You should pass an Infotable with the desired fields formats, or a JSON Infotable, here an example of the second opcion:

 

var fields = { dataShape: {"fieldDefinitions":
 {"fieldName1":
 {"name":"fieldName1", 
 "aspects":{},
 "description":"",
 "baseType":"NUMBER",
 "ordinal":1},
 "fieldName2":
 {"name":"fieldName2",
 "aspects":{},
 "description":"",
 "baseType":"INTEGER",
 "ordinal":2}
 }
 },
 rows: [] 
 };


Resources["EntityServices"].CreateDataShape( {
	name: "newDataShapeName",
	description: undefined ,
	fields: fields,
	tags: undefined
});

1 reply

19-Tanzanite
April 11, 2019

Hello @Sugumar_5656 

 

PFB snippet to add Field Definition to Datashape

 

var params = {
 name: FIELDNAME /* STRING */,
 description: undefined /* STRING */,
 type: 'NUMBER' /* BASETYPENAME */,
 ordinal: undefined /* INTEGER */,
 primaryKey: undefined /* BOOLEAN */,
 dataShape: undefined /* DATASHAPENAME */
 };

 // no return
 DataShapes[DatashapeName].AddFieldDefinition(params);

Regards,
VR

1-Visitor
April 11, 2019

Hai Velkumar,

 

Thank You for your reply.

I already used the snippet what you  shared. It is actually used to add fields one by one to the already created Datashape.

 

But i required to create multiple number of fields when i am creating the data shape itself. 

 

Thanks & Regards

Sugumar R

1-Visitor
April 11, 2019

You should pass an Infotable with the desired fields formats, or a JSON Infotable, here an example of the second opcion:

 

var fields = { dataShape: {"fieldDefinitions":
 {"fieldName1":
 {"name":"fieldName1", 
 "aspects":{},
 "description":"",
 "baseType":"NUMBER",
 "ordinal":1},
 "fieldName2":
 {"name":"fieldName2",
 "aspects":{},
 "description":"",
 "baseType":"INTEGER",
 "ordinal":2}
 }
 },
 rows: [] 
 };


Resources["EntityServices"].CreateDataShape( {
	name: "newDataShapeName",
	description: undefined ,
	fields: fields,
	tags: undefined
});