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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

How to Create Data shape Through Service in Thingworx

Sugumar_5656
14-Alexandrite

How to Create Data shape Through Service in Thingworx

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

ACCEPTED SOLUTION

Accepted Solutions

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
});

View solution in original post

4 REPLIES 4

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

Sugumar_5656
14-Alexandrite
(To:Velkumar)

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

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
});
Sugumar_5656
14-Alexandrite
(To:CarlesColl)

Thank you so much CarlesColl ...

 

Its Working Perfectly CarlesColl .

 

Thanks& Regards

Sugumar R

Announcements


Top Tags