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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Create stream programmatically

skef
12-Amethyst

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?

ACCEPTED SOLUTION

Accepted Solutions
jkaczynski
12-Amethyst
(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
12-Amethyst
(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.

Announcements


Top Tags