Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
I am trying to create a DataTable from a service.
try {
var thingParams = {
name: "MyDataTable",
description: undefined /* STRING */,
thingTemplateName: "DataTable" /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};
// no return
Resources["EntityServices"].CreateThing(thingParams);
Things["MyDataTable"].EnableThing();
Things["MyDataTable"].RestartThing();
Things["MyDataTable"].SetProjectName({ projectName: "MyProject" });
Things["MyDataTable"].SetDataShape({ name: "MyDataShape" });
} catch (err) {
logger.error(me.name + " Service DataTableHelper.WriteToDataTable has an error on line #" + err.lineNumber + ": " + err.message);
}
I get the foolowing error:
DemoFileHelper Service DataTableHelper.WriteToDataTable has an error on line #14: com.thingworx.common.exceptions.InvalidRequestException: Thing [MyDataTable] is not enabled
Line 14 is the one where I set the Project Name.
Any help would be welcomed.
Solved! Go to Solution.
I have moved the setDataShape declaration a bit higher and it seemed to work. (changed the datashape and project name with something on my system).
try {
var thingParams = {
name: "MyDataTable",
description: undefined /* STRING */,
thingTemplateName: "DataTable" /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};
// no return
Resources["EntityServices"].CreateThing(thingParams);
Things["MyDataTable"].EnableThing();
Things["MyDataTable"].SetDataShape({
name: "ad" /* DATASHAPENAME */
});
Things["MyDataTable"].RestartThing();
Things["MyDataTable"].SetProjectName({ projectName: "GitBackup" });
} catch (err) {
logger.error(me.name + " Service DataTableHelper.WriteToDataTable has an error on line #" + err.lineNumber + ": " + err.message);
}
I have moved the setDataShape declaration a bit higher and it seemed to work. (changed the datashape and project name with something on my system).
try {
var thingParams = {
name: "MyDataTable",
description: undefined /* STRING */,
thingTemplateName: "DataTable" /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};
// no return
Resources["EntityServices"].CreateThing(thingParams);
Things["MyDataTable"].EnableThing();
Things["MyDataTable"].SetDataShape({
name: "ad" /* DATASHAPENAME */
});
Things["MyDataTable"].RestartThing();
Things["MyDataTable"].SetProjectName({ projectName: "GitBackup" });
} catch (err) {
logger.error(me.name + " Service DataTableHelper.WriteToDataTable has an error on line #" + err.lineNumber + ": " + err.message);
}
Thank you, it worked!