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

Community email notifications are disrupted. While we are working to resolve, please check on your favorite boards regularly to keep up with your conversations and new topics.

Update Thing's inherited property value through service

sabharees
13-Aquamarine

Update Thing's inherited property value through service

Hi, I have few properties (inherited from my Thing template) in my Thing.

I want to update my Thing's inherited property through service. 

 

I tried :

 

Things[thing].test = "Test Value"; //tried to update value of my test property
result =Things[thing].test; // to check i printed it as result,

 

This method is not working for me ... 

 

1 ACCEPTED SOLUTION

Accepted Solutions
sabharees
13-Aquamarine
(To:sabharees)

Hi,

 

I resolved my problem .. The reason I was not able to update properties is I haven't enabled and restarted my thing after creating it from service. so, i used the below code before passing property values

// logic for creating thing //

Things[''YourThingName"].EnableThing(); //to enable thing
Things[''YourThingName"].RestartThing();//to restart thing

//logic for update property values///

 

Hope, This will help someone someday...... 

View solution in original post

3 REPLIES 3

Hello @sabharees 

I do the test for you in TWX 9.0. 

 

me.Time = 'hello';
result = me.Time;

 

MaxWang_0-1616140786701.png

MaxWang_1-1616140814465.png

 

BR,

Max

 

 

sabharees
13-Aquamarine
(To:Rocket_Max)

Hi Max, Actually I creating thing and updating its property in loop. 

 

I am able to create thing with correct TP but not able to update property values, I using TWX 8.5 

 

for your ref:

 

 

let dataFromCSV = Resources["CSVParserFunctions"].ReadCSVFile(params); // infotable 
for (let x = 0; x < dataFromCSV.rows.length; x++) {
let thingName = "Test_sabharees.N.T";
thingName = thingName.replace("N", customernumber.toString());
try {
Resources["EntityServices"].CreateThing({
name: thingName /* STRING */ ,
description: undefined /* STRING */ ,
thingTemplateName: "test_template" /* THINGTEMPLATENAME */ ,
tags: 'test_sabharees_tag:test_sabharees'
});

Things[thingName].AccessToken = dataFromCSV.rows[x].AccessToken; // text
Things[thingName].APIPassword = encrypt(dataFromCSV.rows[x].APIPassword); //password
Things[thingName].APIScope = dataFromCSV.rows[x].APIScope; //text
Things[thingName].ClientID = dataFromCSV.rows[x].ClientID; //text
Things[thingName].APIUsername = dataFromCSV.rows[x].APIUsername; //text
Things[thingName].ClientSecret = encrypt(dataFromCSV.rows[x].ClientSecret); //password
Things[thingName].CustomerID = dataFromCSV.rows[x].CustomerID; //int
Things[thingName].HeaderAuthorization = encrypt(dataFromCSV.rows[x].HeaderAuthorization); //password
Things[thingName].RESTBaseURL = dataFromCSV.rows[x].RESTBaseURL; //text
result = true;
} catch (err) {
result = false + err.lineNumber + err;
logger.warn(" Service error in " + me.name + err.lineNumber + err);
Resources["EntityServices"].DeleteThing({
name: thingName /* THINGNAME */
});
}
}
} catch (err) {
result = false + err.lineNumber + err;
logger.warn("Service error in " + me.name + err.lineNumber + err);
}

function encrypt(value) {
return Resources["EncryptionServices"].EncryptPropertyValue({
data: value
});
}

sabharees
13-Aquamarine
(To:sabharees)

Hi,

 

I resolved my problem .. The reason I was not able to update properties is I haven't enabled and restarted my thing after creating it from service. so, i used the below code before passing property values

// logic for creating thing //

Things[''YourThingName"].EnableThing(); //to enable thing
Things[''YourThingName"].RestartThing();//to restart thing

//logic for update property values///

 

Hope, This will help someone someday...... 

Top Tags