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 called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Create stream programmatically

skef
11-Garnet

Create stream programmatically

Is there a possibility to create a stream programmatically?

 

According to this thread, I can duplicate a 'prototype' stream, but I have another requirement. I need to create a new stream an I need to choose the data shape of the stream while creating the stream.

 

Is this possible?

1 ACCEPTED SOLUTION

Accepted Solutions
jkaczynski
4-Participant
(To:skef)

Hi @skef,

 

It's surely available:

var name = "YourStreamName";

Resources["EntityServices"].CreateThing({ 
name: name,
description: undefined,
thingTemplateName: "Stream", // this makes a Thing -> Stream
tags: undefined
}); // unfortunately, when doing this, we ends up with a new entity with no DataShape and PersistenceProvider
// so we need to set them manually
Things[name].EnableThing(); Things[name].RestartThing(); Things[name].SetDataShape({ name: "DataShapeWithPrimaryKey" });
// necessary to enable again Things[name].EnableThing(); Things[name].RestartThing();
// setting a default one Things[name].SetPersistenceProvider({ name: "ThingworxPersistenceProvider" }); Things[name].EnableThing(); Things[name].RestartThing();

For me, working on ThingWorx 8.3 - it's working fine, I can add records later.

 

Hope it helps.

BR,

JK.

View solution in original post

1 REPLY 1
jkaczynski
4-Participant
(To:skef)

Hi @skef,

 

It's surely available:

var name = "YourStreamName";

Resources["EntityServices"].CreateThing({ 
name: name,
description: undefined,
thingTemplateName: "Stream", // this makes a Thing -> Stream
tags: undefined
}); // unfortunately, when doing this, we ends up with a new entity with no DataShape and PersistenceProvider
// so we need to set them manually
Things[name].EnableThing(); Things[name].RestartThing(); Things[name].SetDataShape({ name: "DataShapeWithPrimaryKey" });
// necessary to enable again Things[name].EnableThing(); Things[name].RestartThing();
// setting a default one Things[name].SetPersistenceProvider({ name: "ThingworxPersistenceProvider" }); Things[name].EnableThing(); Things[name].RestartThing();

For me, working on ThingWorx 8.3 - it's working fine, I can add records later.

 

Hope it helps.

BR,

JK.

Top Tags