Skip to main content
4-Participant
July 3, 2024
Solved

Set value of property from RemoteThing

  • July 3, 2024
  • 2 replies
  • 1227 views

I have a Thing with some properties from RemoteThings.

The type of the 'IndustrialThing' property is Thing.

LR_11305480_0-1720011726447.png

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

 

 

 

Best answer by Rocko

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.

2 replies

19-Tanzanite
July 4, 2024

HI @LR_11305480 

 

Try below code :

 

Things["THINGNAME"].PROPERTYNAME = "PROPERTYVALUE";

 

/VR

Rocko
Rocko19-TanzaniteAnswer
19-Tanzanite
July 4, 2024

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.

4-Participant
July 4, 2024

Thank you very much, Rocko!

That was exactly the problem with my code.