Variable overwrite or deletion

Hi there,

Some best practice advice it would be very useful here.

I have several variables stored on mutable device that are updated through Analysis.

I have need only of the last value, is there a chance to overwrite the variable or I have to delete the old values monthly?

Thanks in advance!

Hi Viorel,

You can update the already existing variables using the TagoIO SDK!

Using the editData() method you can chose which variable you want to edit.

Hope this helps!

Hey Freddy, that method can work with bot mutable and inmutable buckets? Or just mutable ones?

Edit: nvm I read that it’s only on mutable ones.

@[

Freddy Minuzzi

](https://help.tago.io/portal/en/community/user/264273000027113076) I’ll have a look at that! Thanks!

Team,

This isn’t as easy to use as it looks. I think FIRST, you have to put some data into the store.

The pseudo-code looks something like this:

if( data_doesn’t exist ) { senddata; return }

if( data_exists ) { getdata ; extract_id ; edit_data }

It would be SUPER COOL if you had a:

updateorcreateData( {stuff to update } );

I just got this code (i’m no js expert - just a hack)

//

// using nickname tag, write this dynamic data to the mutable bucket

//

const writeValue = {

variable: myNickname.value,

value: myWaterSoil,

unit: “Percent”,

};

//

// before writing, find out if the variable exists. if it does

// use editData, if it doesn’t use sendData.

//

// to find out if it exists, use getData

//

const readValue = {

variable: myNickname.value,

query: “last_item”,

};

//

// get device data using the nickname

//

const getResult = await outDevice.getData(readValue);

context.log(" from getResult ", getResult );

if( getResult.length ) {

const dataId = getResult[0].id;

context.log(" FOUND - Updating ", dataId );

writeValue[“id”]= dataId;

const Result = await outDevice.editData(writeValue);

}

else {

context.log(" NOT found - Writing ", getResult );

const Result = await outDevice.sendData(writeValue);

}

}

module.exports = new Analysis(init);