Skip to main content
17-Peridot
May 11, 2021
Solved

is RestartThing necessary when creating thing from script service ?

  • May 11, 2021
  • 1 reply
  • 1657 views

Hi, 

According to the posts below : 

https://community.ptc.com/t5/ThingWorx-Developers/Dynamically-create-enable-and-restart-Things-in-a-webservice/td-p/576907

https://community.ptc.com/t5/IoT-Tech-Tips/Creating-a-Thing-in-Service-Script/td-p/533427

 

    var params = {

        name: "NewThingName",

        thingTemplateName: "GenericThing"

    };

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

    Things["NewThingName"].EnableThing();

    Things["NewThingName"].RestartThing();

 

 

The step is CreateThing->EnableThing->RestartThing ,  but in my test , I found thing works well even if I don't call the service RestartThing.   is this step still necessary in ThingWorx 9.1.0  ?    

 

Regards,

Sean

 

Best answer by mgoel

@seanccc 

 

Thanks for reaching out to us. I just test the below code in 9.1 version.


let params = {
name: 'MG2' /* STRING */,
description: undefined /* STRING */,
thingTemplateName: 'GenericThing' /* THINGTEMPLATENAME */,
projectName: 'PTCDefaultProject' /* PROJECTNAME */,
tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateThing(params);
Things["MG2"].EnableThing();

 

Thing is enabled after running this, no need to restart. By default project is Mandatory in Thingworx 9.1 version. Hope this is your answer.

 

Regards,

Mohit

1 reply

mgoel5-Regular MemberAnswer
5-Regular Member
May 11, 2021

@seanccc 

 

Thanks for reaching out to us. I just test the below code in 9.1 version.


let params = {
name: 'MG2' /* STRING */,
description: undefined /* STRING */,
thingTemplateName: 'GenericThing' /* THINGTEMPLATENAME */,
projectName: 'PTCDefaultProject' /* PROJECTNAME */,
tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateThing(params);
Things["MG2"].EnableThing();

 

Thing is enabled after running this, no need to restart. By default project is Mandatory in Thingworx 9.1 version. Hope this is your answer.

 

Regards,

Mohit

5-Regular Member
May 12, 2021

Hi @seanccc 

 

If you feel above response is the resolution of your query, could you please mark it as accept solution for the benefit of other community members.

 

Regards,

Mohit