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

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

Thing is not enabled even though EnableThing/RestartThing is called

cmelancon
7-Bedrock

Thing is not enabled even though EnableThing/RestartThing is called

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.

ACCEPTED SOLUTION

Accepted Solutions

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

 

 

View solution in original post

2 REPLIES 2

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!

Announcements


Top Tags