Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Pls, help on code which dynamically create a thing and assign new ValueStream also.
The code is as shown:-
var params = {
name: me.name+"-GW" /* STRING */,
description: undefined /* STRING */,
thingTemplateName: "GenericThing" /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};
// no return
Resources["EntityServices"].CreateThing(params);
Things[me.name+"-GW"].EnableThing();
Things[me.name+"-GW"].RestartThing();
var params = {
name: "ValueStream_"+me.name+"-GW" /* STRING */,
description: undefined /* STRING */,
thingTemplateName: "ValueStream" /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};
// no return
Resources["EntityServices"].CreateThing(params);
var params = {
name: "ValueStream_"+me.name+"-GW" /* THINGNAME */
};
Things[me.name+"-GW"].SetValueStream(params);
Thanks in advance
Hi ,
You can try using below code, It works for me
var text =me.name+"-GW";
var text1= "ValueStream_"+me.name+"-GW";
try {
var params = {
name: text /* STRING */,
description: undefined /* STRING */,
thingTemplateName: "GenericThing" /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};
Resources["EntityServices"].CreateThing(params);
}
catch(err) {
logger.warn(err.message);
}
try {
Things[text].EnableThing();
}
catch(err) {
logger.warn(err.message);
}
try {
Things[text].RestartThing();
}
catch(err) {
logger.warn(err.message);
}
try {
var params1 = {
name: text1 /* STRING */,
description: undefined /* STRING */,
thingTemplateName: "ValueStream" /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};
// no return
Resources["EntityServices"].CreateThing(params1);
}
catch(err) {
logger.warn(err.message);
}
try {
Things[text1].EnableThing();
}
catch(err) {
logger.warn(err.message);
}
try {
Things[text1].RestartThing();
}
catch(err) {
logger.warn(err.message);
}
try {
var params2 = {
name: text1 /* THINGNAME */
};
Things[text].SetValueStream(params2);
}
catch(err) {
logger.warn(err.message);
}
try {
Things[text].EnableThing();
}
catch(err) {
logger.warn(err.message);
}
try {
Things[text].RestartThing();
}
catch(err) {
logger.warn(err.message);
}