Skip to main content
12-Amethyst
April 14, 2017
Question

Create template by snippet

  • April 14, 2017
  • 6 replies
  • 2428 views

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

5-Regular Member
April 14, 2017

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).

aziliotto12-AmethystAuthor
12-Amethyst
April 21, 2017

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...

5-Regular Member
October 13, 2017

I am having the same Issue.