Skip to main content
1-Visitor
July 25, 2018
Solved

Create stream programmatically

  • July 25, 2018
  • 1 reply
  • 2018 views

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?

Best answer by jkaczynski

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.

1 reply

1-Visitor
July 26, 2018

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.