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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Create template by snippet

aziliotto
4-Participant

Create template by snippet

Hi, i need to create a template by snippet.

I figured out this method but i can't see on the template list my new template and if i try to recreate it i receive the message "can't create template 'MyCustomNameTemplate' template already exist", i had this problem when i tryed to create a thing but i didn't restart it and enable it. Is there any similar method for templates ?

var paramsRemoteThing = {

    name: "MyCustomNameTemplate",

    description: "my personal description",

    thingTemplateName: 'RemoteThing',

    tags: 'MyApp:Template'

};

Resources["EntityServices"].CreateThingTemplate(paramsRemoteThing);

//here i need some code for enable template and see it in the template's list.

thank you !!!

6 REPLIES 6

Alberto, was that snippet part of a service that failed? If it says 'template already exists' and you can't see it, you've essentially created a ghost entity; that's an entity that exists in memory but is not committed to the database. You would always need to use a try-catch block around create scripts so that you avoid creating ghost entities.

If you have ThingWorx 7.2.0+, please take a look at our Ghost Entities Cleaner extension in our Marketplace. Here is a KCS article that expands on the topic of detection, prevention and removal of said entities. With that being said, the create code you provided should work (on its own).

aziliotto
4-Participant
(To:Aanjan)

No the script did'nt failed, and for solving ghost entities i stopped tomcat and restart.

But also with try catch i can't see the template on the template list so i imagine there is some code to enable it like creating things...

aziliotto
4-Participant
(To:Aanjan)

Anyone give me some help please?

supandey
19-Tanzanite
(To:aziliotto)

Alberto i just tried reproducing this but it's working just fine (tested on 7.4.0), which TWX version are you on and with what user are you logged in to execute this?

var params = {

  name: "DemoThingTemplate2" /* STRING */,

  description: "demoThing" /* STRING */,

  thingTemplateName: "RemoteThing" /* THINGTEMPLATENAME */,

  tags: undefined /* TAGS */

};

// no return

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

posipova
20-Turquoise
(To:aziliotto)

I was able to create it using your exact code/snippet in a service. You don't need to enable it like when creating things:

Do you see any errors in the Application log?

What version of Thingworx are you using? Versions of Tomcat and Java? Have you tried in a different browser?

vxavier
13-Aquamarine
(To:aziliotto)

I am having the same Issue.

Top Tags