ThingsBoards How to change an server attribute using the custom action option in a widget

Is it possible to change an server attribute using the custom action option in a widget? Thanks for help

enter image description here

Upvotes: 0

Views: 839

Answers (1)

devaskim
devaskim

Reputation: 559

let attributeService = widgetContext.$injector.get(widgetContext.servicesMap.get('attributeService'));

let attributes = [{
    "key": YOUR_ATTRIBUTE_KEY,
    "value": YOUR_ATTRIBUTE_VALUE
}];
attributeService.saveEntityAttributes(entityId, 'SERVER_SCOPE', attributes).
    subscribe(
        () => {
            console.log('Saved!');
        },
        error => {
            console.log('Error');
        }
    );

Upvotes: 0

Related Questions