Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hello, I am creating things programatically and created. but the issue is am not able to make active, cannot able to set value stream and also cannot able to see. this is my code what I have written.
var paramsTH = {
//name: "F-"+i,
name: values.ConnectionID, // I will give the name based on the value of ConnectionID
thingTemplateName: 'EnergyMeters',
//tags: tags
};
Resources["EntityServices"].CreateThing(paramsTH);
Things[values.ConnectionID].SetValueStream({ name: "Process Value Stream" }); // I need to set this value stream name to my thing automatically when I created
Things[values.ConnectionID].Enable(); or Things[values.ConnectionID].EnableThing(); // I have used both the code but not worked
Things[values.ConnectionID].RestartThing();
logger.warn("Thing created");
after running this code thing is creating but rest of the things cannot be happened and finally I cannot able to see that thing except in GetEntityList service and at Application log
Solved! Go to Solution.
You have to create the thing, enable and restart it, then assign a value stream. The following code works:
var params = {
name: "NewThing4"/* STRING */,
thingTemplateName: "GenericThing" /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};
// no return
Resources["EntityServices"].CreateThing(params);
Things['NewThing4'].EnableThing();
Things['NewThing4'].RestartThing();
var params = {
name: "NewVa" /* THINGNAME */
};
// no return
Things["NewThing4"].SetValueStream(params);
You have to create the thing, enable and restart it, then assign a value stream. The following code works:
var params = {
name: "NewThing4"/* STRING */,
thingTemplateName: "GenericThing" /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};
// no return
Resources["EntityServices"].CreateThing(params);
Things['NewThing4'].EnableThing();
Things['NewThing4'].RestartThing();
var params = {
name: "NewVa" /* THINGNAME */
};
// no return
Things["NewThing4"].SetValueStream(params);
Thanks for Replying,
I tried the code as you mentioned in the previous reply but could not able to enable,restart and setting the value stream and also not able to see that thing in my List of Things.
I will elaborate little bit about this code
var paramsTH = {
name: values.ConnectionID, // Here am giving the Thing name dynamically which is mentioned in the property name ConnectionID
thingTemplateName: "EnergyMeters", // This is the template where I have created all the properties and services.
//tags: tags
};
Resources["EntityServices"].CreateThing(paramsTH); // after this execution code Thing is created successfully
// the issue is coming only when I execute the below code for Enable and Restart and the Thing become invisible.
Things[values.ConnectionID].EnableThing();
Things[values.ConnectionID].RestartThing();
var paramsvs = {
name: "Process Value Stream" /* THINGNAME */ // Process Value Stream is the name of value stream am going to assign for the things.
};
Things[values.ConnectionID].SetValueStream(paramsvs);
Note : In Template I have assign the value stream, as per Template concept those who are implementing the template should get inherited all the properties as well as settings. is that correct as per my understanding.
waiting for your reply
Thanks Polina,
Now ITs working successfully executing all the code.