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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Set value of property from RemoteThing

LR_11305480
3-Newcomer

Set value of property from RemoteThing

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

 

 

 

ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

3 REPLIES 3

HI @LR_11305480 

 

Try below code :

 

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

 

/VR

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.

LR_11305480
3-Newcomer
(To:Rocko)

Thank you very much, Rocko!

That was exactly the problem with my code.

Announcements


Top Tags