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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Overwriting an Infotable Property

agondek
12-Amethyst

Overwriting an Infotable Property

I have the following code with which i never assign the variable back to the property however my property on the "Thing" changes to match the service result. Does anyone know why this is happening?

var original=Things["Thing"].Property;
var variable=original;

var newField = new Object();
newField.name = "Setpoint";
newField.baseType = 'STRING';
variable.AddField(newField);

for (var i=0;i<variable.rows.length;i++){
    variable.rows[i].Setpoint=/*somevalue*/;
}
var result=variable;
ACCEPTED SOLUTION

Accepted Solutions

Doing that:

var original=Things["Thing"].Property;

or that:

var variable=original;

 you don't clone Property contents, you get a reference to it, that's why property it's changing, if you want to work with a cloned copy:

var variable = Resources["InfotableFunctions"].Clone({ t1: original });

View solution in original post

4 REPLIES 4

Doing that:

var original=Things["Thing"].Property;

or that:

var variable=original;

 you don't clone Property contents, you get a reference to it, that's why property it's changing, if you want to work with a cloned copy:

var variable = Resources["InfotableFunctions"].Clone({ t1: original });
agondek
12-Amethyst
(To:CarlesColl)

Hi Carles,

 

That makes sense as far as cloning goes. What troubles me is that operations on a variable in my service only impact infotable type properties. For example, if I use a number property as a reference and then proceed to multiply the variable by 20, in my service, the corresponding property value is not multiplied by 20 unless I assign the variable value to the property.

PaiChung
22-Sapphire I
(To:agondek)

Infotable properties indeed are treated a bit different as well as XML and JSON properties.

This is also why you have to specifically write back the full table to update the property if persisted.

agondek
12-Amethyst
(To:PaiChung)

Fair enough. Thanks Pai and Carles!

Announcements


Top Tags