Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
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();
Solved! Go to Solution.
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);
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);