# Edit Tags for a Specific Device

**URL:** https://community.tago.io/t/edit-tags-for-a-specific-device/1470
**Category:** Analysis and Actions
**Created:** [September 27, 2023, 5:48pm UTC](https://community.tago.io/t/edit-tags-for-a-specific-device/1470 "2023-09-27T17:48:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![octaviosanchez.alumn](https://avatars.discourse-cdn.com/v4/letter/o/ec9cab/32.png) [@octaviosanchez.alumn](https://community.tago.io/u/octaviosanchez.alumn)
#### Post date: [September 27, 2023, 5:48pm UTC](https://community.tago.io/t/edit-tags-for-a-specific-device/1470/1 "2023-09-27T17:48:07Z")

</div>

In the following code I am creating a device from a form on blueprint devices with their corresponding labels. But now what I would like is to be able to edit that data from the device labels.

 ![](https://canada1.discourse-cdn.com/flex034/uploads/tagoio1/original/2X/2/29504fad32032b4cdfe687046e240b0584a989cf.png)

const { Analysis, Account, Utils, Device } = require(“@tago-io/sdk”);

async function startAnalysis(context, scope) {

if (!scope[0]) {

```
return context.log("The analysis must be triggered by a widget.");

```

}

context.log(“Creating your device”);

const env = Utils.envToJson(context.environment);

if (!env.account\_token) return context.log(‘Missing “account\_token” environment variable’);

else if (env.account\_token.length !== 36) return context.log(‘Invalid “account\_token” in the environment variable’);

const account = new Account({ token: env.account\_token });

const dashboard\_dev\_token = await Utils.getTokenByName(account, scope[0].device);

const dashboard\_device = new Device({ token: dashboard\_dev\_token });

const network\_id = scope.find((x) =\> x.variable === “device\_network”);

const connector\_id = scope.find((x) =\> x.variable === “device\_connector”);

const device\_name = scope.find((x) =\> x.variable === “id\_tienda”);

const nombre = scope.find((x) =\> x.variable === “nombre”);

const device\_eui = scope.find((x) =\> x.variable === “id\_tienda”);

const region = scope.find((x) =\> x.variable === “region”);

const zona = scope.find((x) =\> x.variable === “zona”);

const tamano = scope.find((x) =\> x.variable === “tamano”);

const status = scope.find((x) =\> x.variable === “status\_operativo”);

const direccion = scope.find((x) =\> x.variable === “direccion”);

const email = scope.find((x) =\> x.variable === “email”);

const tienda\_user = scope.find((x) =\> x.variable === “tienda\_user”);

const solar\_activa = scope.find((x) =\> x.variable === “solar\_activa”);

const check\_eolica = scope.find((x) =\> x.variable === “check\_eolica”);

const entidad = scope.find((x) =\> x.variable === “entidad”);

const cp = scope.find((x) =\> x.variable === “cp”);

const gerente = scope.find((x) =\> x.variable === “gerente”);

const id\_cont = scope.find((x) =\> x.variable === “id\_cont”);

const carga = scope.find((x) =\> x.variable === “carga”);

const demanda = scope.find((x) =\> x.variable === “demanda”);

const no\_medidor = scope.find((x) =\> x.variable === “no\_medidor”);

const tarifa = scope.find((x) =\> x.variable === “tarifa”);

const multiplicador = scope.find((x) =\> x.variable === “multiplicador”);

const facturacion = scope.find((x) =\> x.variable === “facturacion”);

if (!connector\_id || !connector\_id.value) {

```
return context.log('Missing "device\_connector" in the data scope.');

```

} else if (!network\_id || !network\_id.value) {

```
return context.log('Missing "device\_network" in the data scope.');

```

} else if (!device\_eui || !device\_eui.value) {

```
return context.log('Missing "device\_eui" in the data scope.');

```

}

const result = await account.devices

```
.create({

  name: device\_name.value,

  serie\_number: device\_eui.value,

  tags: \[

    { key: "CUENTA", value: "RETAIL" },

    { key: "TIENDA", value: nombre.value },

    { key: "device\_eui", value: device\_eui.value },

    { key: "REGION", value: region.value },

    { key: "ZONA", value: zona.value },

    { key: "TAMAÑO", value: tamano.value },

    { key: "ESTADO", value: status.value },

    { key: "DIRECCION", value: direccion.value },

    { key: "SOLAR", value: solar\_activa ? solar\_activa.value.toString() : '' },

    { key: "EOLICA", value: check\_eolica ? check\_eolica.value.toString() : '' },

  \],

  connector: connector\_id.value,

  network: network\_id.value,

  active: true,

  type: "mutable",

  chunk\_period: "month",

  chunk\_retention: 13,

})

.catch((error) \=> {

  dashboard\_device.sendData({ variable: "validation", value: \`Error when creating the device ${error}\`, metadata: { color: "red" } });

  throw error;

});

```

---

<div class="post-metadata">

### Author: ![mateus.silva](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@mateus.silva](https://community.tago.io/u/mateus.silva)
#### Post date: [September 27, 2023, 7:37pm UTC](https://community.tago.io/t/edit-tags-for-a-specific-device/1470/2 "2023-09-27T19:37:56Z")

</div>

To access this feature, you’ll need to create a widget of the ‘ **Device List** ’ type. You can find step-by-step instructions on how to do this in the following tutorial:  
[Tutorial on Creating a Device List Widget.](https://help.tago.io/portal/en/kb/articles/527-device-list-widget#4_Editing_device_parameters)
