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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Thing is showing as created when we run DoesThingExists but unable to display in composer

ranjank
15-Moonstone

Thing is showing as created when we run DoesThingExists but unable to display in composer

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

 

1 REPLY 1
vinakumar
12-Amethyst
(To:ranjank)

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);
}

Announcements


Top Tags