Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
I have a Thing with some properties from RemoteThings.
The type of the 'IndustrialThing' property is Thing.
Manually, I can set the value to 'ANOTHERTHING' if I want to, but I want to set it through a service using code.
I've tried the code below, it gives no errors, but it doesn't work.
var params = {
propertyName: 'IndustrialThing',
propertyValue: 'ANOTHERTHING'
};
Things['MYTHING'].SetPropertyValues(params);
Solved! Go to Solution.
The issue is most probably that SetPropertyValues (notice the plural for setting multiple values) expects you to provide an infotable for all the properties and values you want to set. The code you provided just passes over a simple object.
The valid code would be something along this:
let t = Resources["InfoTableFunctions"].CreateInfoTable();
t.AddField({name: "IndustrialThing", baseType: 'THINGNAME'});
t.AddRow({IndustrialThing:"ANOTHERTHING"});
Things["MYTHING"].SetPropertyValues({values: t});
Maybe Velkumar's suggestion is the better way to go.
The issue is most probably that SetPropertyValues (notice the plural for setting multiple values) expects you to provide an infotable for all the properties and values you want to set. The code you provided just passes over a simple object.
The valid code would be something along this:
let t = Resources["InfoTableFunctions"].CreateInfoTable();
t.AddField({name: "IndustrialThing", baseType: 'THINGNAME'});
t.AddRow({IndustrialThing:"ANOTHERTHING"});
Things["MYTHING"].SetPropertyValues({values: t});
Maybe Velkumar's suggestion is the better way to go.
Thank you very much, Rocko!
That was exactly the problem with my code.