Skip to main content
pshashipreetham
18-Opal
18-Opal
June 7, 2023
Solved

How to Enable a Thing in the code

  • June 7, 2023
  • 2 replies
  • 1232 views

Hi,

 

I am trying to create a Thing and assigning a value to the Properties that are inherited from the Thing Template, below is the code.

 

Resources["EntityServices"].CreateThing({
	name: "testfty" /* STRING */,
 thingTemplateName: "testfty.TT.testfty" /* THINGTEMPLATENAME */,
	projectName: "comP" /* PROJECTNAME */,
});

Things["testfty"].Enable();
Things["testfty"].Restart();

Things["testfty"].Property1= 32;
Things["testfty"].Property2= 56;

 

But I am getting the following error:

 

Error executing service addSensor. Message :: TypeError: Cannot find function Enable in object com.thingworx.things.ConfiguredThing@a3e81bb. - See Script Error Log for more details.

 

 


Thanks,

 

 

Best answer by ashaban

 

Please use EnableThing/RestartThing
Things["testfty"].Enable(); --> Things["testfty"].EnableThing();
Things["testfty"].Restart(); --> Things["testfty"].RestartThing();

 

2 replies

ashaban12-AmethystAnswer
12-Amethyst
June 7, 2023

 

Please use EnableThing/RestartThing
Things["testfty"].Enable(); --> Things["testfty"].EnableThing();
Things["testfty"].Restart(); --> Things["testfty"].RestartThing();

 

19-Tanzanite
June 8, 2023

And, as a reminder for others in case of similar situations, all the Services available for a Thing are available in the Services section, so you can verify it a service with that name exists there, OR in the service editor you can select as a reference another entity, and at this point you will also see all its services.

VladimirRosu_0-1686209683248.png