Skip to main content
1-Visitor
July 18, 2016
Question

How to create Things and Things template by code

  • July 18, 2016
  • 1 reply
  • 10684 views

There's something I don't understand:
I would like to create my thing by code on eclipse instead of by composer.

I can't find a tutorial which explain how to do this. Would you have a link?

1 reply

1-Visitor
July 18, 2016

Hi Fabio,

I've never did it from Java extension, but you should be able to call Resources["EntityServices"].CreateThing service from Java side.

Carles.

fmanniti1-VisitorAuthor
1-Visitor
July 18, 2016

Yes, but what you are talking about is inside thing services, isn't it?

I mean, I have this "issue": I have a thing template with 1000 things child I can't just create them one by one so I was thinking about a java extension.

What I've done so far is:

Create the Thing template: MyThingTemplate

Create a Thing builder: MyThingBuilder.

Inside MyThingBuilder there is a subscription at thing start


for(i=1; i<1001; i++){

     var paramsTH = {

       name: "myThing_"+i,

       thingTemplateName: 'MyThingTemplate',

       tags: tags

     };

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

}

I know that this works. My only issue is that this is not the smartest way to do this.

1-Visitor
July 18, 2016

I don't see why you need an extension to do this, you can perfectly do with a helper thing ( MyThingBuilder ) it's totally correct.

What I don't know it's why you should bind this service to the Thing Start event, this service should be called only once, then you can perfectly call it by hand. If you want to be more Pro, you can build a Helper Thing which initializes all you system, which triggers any Initialization process the First time only.