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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Code problems with Datashape/table

AnselmoSilSaito
12-Amethyst

Code problems with Datashape/table

Hi All,

I am trying to create a service that creates a datatable and also its datashape ( from an transposed infotable created from inputed user data).
The question is...why this code doesnt work?

// FOR DATATABLE CREATION
var params = {

name: "Thing_Name"/* STRING */,

description: undefined /* STRING */,

thingTemplateName: "DataTable" /* THINGTEMPLATENAME */,

tags: undefined /* TAGS */

};

// no return

Resources["EntityServices"].CreateThing(params);

 

//INFOTABLE WITH SOME DATA FROM USER
var paramsu = {
maxItems: undefined /* NUMBER */
};
var tablete = me.GetDataTableEntries(paramsu);

 

//TRANSPOSED INFOTABLE FOR DATASHAPE
var p = {
infoTableName: undefined /* STRING */
};
var trans= Resources["InfoTableFunctions"].CreateInfoTable(p);

for( var i = 0;i< tablete.getRowCount();i++){
trans.AddField({name: tablete[i].nome, baseType: "STRING"});
}
//DATASHAPE creation
var par = {
name: "myds" /* STRING */,
description: undefined /* STRING */,
fields: trans/* INFOTABLE */,
tags: undefined /* TAGS */
};
Resources["EntityServices"].CreateDataShape(par);

Things["Thing_Name"].SetDataShape({ name: "myds" });
Things["Thing_Name"].EnableThing();
Things["Thing_Name"].RestartThing();

1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

 

For Datatable, datashape should contain one primary key.

 

Can you make sure, you have assigned PrimaryKey to your Datashape?

 

And you can also use below code to Create and AddFieldDefinition to your Datashape

 

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

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

/******* ADD FIELD DEFINITION TO DATASHAPE *****/
// Note: Datashape should contain one PrimaryKey for DataTable
var params = {
name: "TestField" /* STRING */,
description: undefined /* STRING */,
type: "STRING" /* BASETYPENAME */,
ordinal: undefined /* INTEGER */,
primaryKey: true /* BOOLEAN */,
dataShape: undefined /* DATASHAPENAME */
};

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

 

View solution in original post

1 REPLY 1

Hi,

 

For Datatable, datashape should contain one primary key.

 

Can you make sure, you have assigned PrimaryKey to your Datashape?

 

And you can also use below code to Create and AddFieldDefinition to your Datashape

 

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

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

/******* ADD FIELD DEFINITION TO DATASHAPE *****/
// Note: Datashape should contain one PrimaryKey for DataTable
var params = {
name: "TestField" /* STRING */,
description: undefined /* STRING */,
type: "STRING" /* BASETYPENAME */,
ordinal: undefined /* INTEGER */,
primaryKey: true /* BOOLEAN */,
dataShape: undefined /* DATASHAPENAME */
};

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

 

Top Tags