# Stored in a global token

**URL:** <https://community.homey.app/t/stored-in-a-global-token/57981>\
**Category:** Developers\
**Created:** [January 7, 2022, 8:33am UTC](https://community.homey.app/t/stored-in-a-global-token/57981 "2022-01-07T08:33:59Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jens\_De\_Smet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jens_de_smet/32/33978_2.png) [@Jens\_De\_Smet](https://community.homey.app/u/Jens_De_Smet)\
**Post date:** [January 7, 2022, 8:33am UTC](https://community.homey.app/t/stored-in-a-global-token/57981/1 "2022-01-07T08:33:59Z")

</div>

I want two input fields to be subtracted from each other and then stored in a global token.

this must be in a dan card.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 7, 2022, 8:39am UTC](https://community.homey.app/t/stored-in-a-global-token/57981/2 "2022-01-07T08:39:13Z")

</div>

What have you tried? What isn’t working? What don’t you understand? Where is your code?

You have been posting variations of the same question for days now.

---

<div class="post-metadata">

**Author:** ![Jens\_De\_Smet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jens_de_smet/32/33978_2.png) [@Jens\_De\_Smet](https://community.homey.app/u/Jens_De_Smet)\
**Post date:** [January 7, 2022, 8:48am UTC](https://community.homey.app/t/stored-in-a-global-token/57981/3 "2022-01-07T08:48:05Z")

</div>

```auto
module.exports = async (options) => {

  const { app, args } = options;

  const w = Number(args.number_1);

  const x = Number(args.number_2);

  const y = (args.Answer);

  const y = await this.homey.flow.createToken(`${y}`, {

   

    type: "number",

    title: `${y}`,

  });

  const z = (w + x);

  const result = (z === y);

  app.log(`The sum of ( ${w} + ${x} ) = ( ${z} = ${result} )`);

  await myToken.setValue(result);

}

```

this is the basic version, this is to test and then work out further, but the basics don’t work yet.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/4/b47522da5b7190c230ec1f2b3692698066d1e8d7.png)

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 7, 2022, 8:56am UTC](https://community.homey.app/t/stored-in-a-global-token/57981/4 "2022-01-07T08:56:15Z")

</div>

You can’t declare a const twice (`y`) to begin with. But your `app.json` is invalid, hence the errors.

---

<div class="post-metadata">

**Author:** ![Jens\_De\_Smet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jens_de_smet/32/33978_2.png) [@Jens\_De\_Smet](https://community.homey.app/u/Jens_De_Smet)\
**Post date:** [January 7, 2022, 8:59am UTC](https://community.homey.app/t/stored-in-a-global-token/57981/5 "2022-01-07T08:59:41Z")

</div>

> [@robertklep](#):
>
> You can’t declare a const twice ( `y` ) to begin with. But your `app.json` is invalid, hence the errors.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/d/ed219d4df2d01bc0c9d3e3cb366a7436f057b6f4.png)

---

<div class="post-metadata">

**Author:** ![Jens\_De\_Smet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jens_de_smet/32/33978_2.png) [@Jens\_De\_Smet](https://community.homey.app/u/Jens_De_Smet)\
**Post date:** [January 7, 2022, 9:26am UTC](https://community.homey.app/t/stored-in-a-global-token/57981/6 "2022-01-07T09:26:57Z")

</div>

```auto
module.exports = async (options) => {

  const { app, args } = options;

  const w = Number(args.number_1);

  const x = Number(args.number_2);

  const y = (args.Answer);

  const z = await this.homey.flow.createToken(`${y}`, {

    type: "number",

    title: `${y}`,

  });

  const z = (w + x);

  const result = (z === y);

  app.log(`The sum of ( ${w} + ${x} ) = ( ${z} = ${result} )`);

  await z.setValue(result);

}

```

```auto
{

  "id": "sum_of_two_numbers",

  "title": {

    "en": "sum of two numbers",

    "nl": "som van twee getallen",

    "de": "summe von zwei Zahlen",

    "fr": "somme de deux nombres",

    "it": "somma di due numeri",

    "sv": "summa av två nummer",

    "no": "sum av to tall",

    "es": "suma de dos números",

    "da": "sum af to tal"

  },

  "hint": {

    "en": "Sum of two numbers is equal to ...",

    "nl": "Som van twee getallen gelijk is aan ...",

    "de": "Summe zweier Zahlen gleich ist ...",

    "fr": "Somme de deux nombres est égale à ...",

    "it": "Somma di due numeri è uguale a ...",

    "sv": "Summa av två tal är lika med ...",

    "no": "Sum av to tall er lik ...",

    "es": "Suma de dos números es igual a ...",

    "da": "Sum af to tal er lig med ..."

  },

  "titleFormatted": {

    "en": "Operation [[number_1]] + [[number_2]] = [[Answer]] (sum)",

    "nl": "Bewerking [[number_1]] + [[number_2]] = [[Answer]] (som)",

    "de": "Operation [[number_1]] + [[number_2]] = [[Answer]] (summe)",

    "fr": "L'opération [[number_1]] + [[number_2]] = [[Answer]] (somme)",

    "it": "L'operazione [[number_1]] + [[number_2]] = [[Answer]] (somma)",

    "sv": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (summa)",

    "no": "Operasjonen [[number_1]] + [[number_2]] = [[Answer]] (sum)",

    "es": "La operación [[number_1]] + [[number_2]] = [[Answer]] (suma)",

    "da": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (sum)"

  },

  "args": [

    {

      "name": "number_1",

      "type": "number",

      "placeholder": {

        "en": "Number 1",

        "nl": "Nummer 1",

        "de": "Nummer 1",

        "fr": "Numéro 1",

        "it": "Numero 1",

        "sv": "Nummer 1",

        "no": "Nummer 1",

        "es": "Numero 1",

        "da": "Nummer 1"

      },

      "min": 0,

      "max": 9999999999,

      "step": 1e-7

    },

    {

      "name": "number_2",

      "type": "number",

      "placeholder": {

        "en": "Number 2",

        "nl": "Nummer 2",

        "de": "Nummer 2",

        "fr": "Numéro 2",

        "it": "Numero 2",

        "sv": "Nummer 2",

        "no": "Nummer 2",

        "es": "Numero 2",

        "da": "Nummer 2"

      },

      "min": 0,

      "max": 9999999999,

      "step": 1e-7

    },

    {

      "type": "droptoken",

      "name": "Answer"

    }

  ]

}

```

```auto
{
        "id": "sum_of_two_numbers",
        "title": {
          "en": "sum of two numbers",
          "nl": "som van twee getallen",
          "de": "summe von zwei Zahlen",
          "fr": "somme de deux nombres",
          "it": "somma di due numeri",
          "sv": "summa av två nummer",
          "no": "sum av to tall",
          "es": "suma de dos números",
          "da": "sum af to tal"
        },
        "hint": {
          "en": "Sum of two numbers is equal to ...",
          "nl": "Som van twee getallen gelijk is aan ...",
          "de": "Summe zweier Zahlen gleich ist ...",
          "fr": "Somme de deux nombres est égale à ...",
          "it": "Somma di due numeri è uguale a ...",
          "sv": "Summa av två tal är lika med ...",
          "no": "Sum av to tall er lik ...",
          "es": "Suma de dos números es igual a ...",
          "da": "Sum af to tal er lig med ..."
        },
        "titleFormatted": {
          "en": "Operation [[number_1]] + [[number_2]] = [[Answer]] (sum)",
          "nl": "Bewerking [[number_1]] + [[number_2]] = [[Answer]] (som)",
          "de": "Operation [[number_1]] + [[number_2]] = [[Answer]] (summe)",
          "fr": "L'opération [[number_1]] + [[number_2]] = [[Answer]] (somme)",
          "it": "L'operazione [[number_1]] + [[number_2]] = [[Answer]] (somma)",
          "sv": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (summa)",
          "no": "Operasjonen [[number_1]] + [[number_2]] = [[Answer]] (sum)",
          "es": "La operación [[number_1]] + [[number_2]] = [[Answer]] (suma)",
          "da": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (sum)"
        },
        "args": [
          {
            "name": "number_1",
            "type": "number",
            "placeholder": {
              "en": "Number 1",
              "nl": "Nummer 1",
              "de": "Nummer 1",
              "fr": "Numéro 1",
              "it": "Numero 1",
              "sv": "Nummer 1",
              "no": "Nummer 1",
              "es": "Numero 1",
              "da": "Nummer 1"
            },
            "min": 0,
            "max": 9999999999,
            "step": 1e-7
          },
          {
            "name": "number_2",
            "type": "number",
            "placeholder": {
              "en": "Number 2",
              "nl": "Nummer 2",
              "de": "Nummer 2",
              "fr": "Numéro 2",
              "it": "Numero 2",
              "sv": "Nummer 2",
              "no": "Nummer 2",
              "es": "Numero 2",
              "da": "Nummer 2"
            },
            "min": 0,
            "max": 9999999999,
            "step": 1e-7
          },
          {
            "type": "droptoken",
            "name": "Answer"
          }
        ]
      }

```

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 7, 2022, 9:29am UTC](https://community.homey.app/t/stored-in-a-global-token/57981/7 "2022-01-07T09:29:55Z")

</div>

> [@Jens\_De\_Smet](#):
>
> ```auto
> {
> "type": "droptoken",
> "name": "Answer"
> }
> 
> ```

Please read the relevant documentation.

---

<div class="post-metadata">

**Author:** ![Jens\_De\_Smet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jens_de_smet/32/33978_2.png) [@Jens\_De\_Smet](https://community.homey.app/u/Jens_De_Smet)\
**Post date:** [January 7, 2022, 11:29am UTC](https://community.homey.app/t/stored-in-a-global-token/57981/9 "2022-01-07T11:29:09Z")

</div>

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/d/bdacea3c60f38c45956ecd83262dbc6bd7fdf890.png)

```auto
module.exports = async (options) => {

  const { app, args } = options;

  const w = Number(args.number_1);

  const x = Number(args.number_2);

  const y = (args.Answer);

  const z = await this.homey.flow.createToken(`${y}`, {

    type: "number",

    title: `${y}`,

  });

  const z = (w + x);

  const result = (Number(z) === Number(y));

  app.log(`The sum of ( ${w} + ${x} ) = ( ${z} = ${result} )`);

  await z.setValue(result);

}

```

```auto
{
  "id": "sum_of_two_numbers",
  "title": {
    "en": "sum of two numbers",
    "nl": "som van twee getallen",
    "de": "summe von zwei Zahlen",
    "fr": "somme de deux nombres",
    "it": "somma di due numeri",
    "sv": "summa av två nummer",
    "no": "sum av to tall",
    "es": "suma de dos números",
    "da": "sum af to tal"
  },
  "hint": {
    "en": "Sum of two numbers is equal to ...",
    "nl": "Som van twee getallen gelijk is aan ...",
    "de": "Summe zweier Zahlen gleich ist ...",
    "fr": "Somme de deux nombres est égale à ...",
    "it": "Somma di due numeri è uguale a ...",
    "sv": "Summa av två tal är lika med ...",
    "no": "Sum av to tall er lik ...",
    "es": "Suma de dos números es igual a ...",
    "da": "Sum af to tal er lig med ..."
  },
  "titleFormatted": {
    "en": "Operation [[number_1]] + [[number_2]] = [[Answer]] (sum)",
    "nl": "Bewerking [[number_1]] + [[number_2]] = [[Answer]] (som)",
    "de": "Operation [[number_1]] + [[number_2]] = [[Answer]] (summe)",
    "fr": "L'opération [[number_1]] + [[number_2]] = [[Answer]] (somme)",
    "it": "L'operazione [[number_1]] + [[number_2]] = [[Answer]] (somma)",
    "sv": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (summa)",
    "no": "Operasjonen [[number_1]] + [[number_2]] = [[Answer]] (sum)",
    "es": "La operación [[number_1]] + [[number_2]] = [[Answer]] (suma)",
    "da": "Operationen [[number_1]] + [[number_2]] = [[Answer]] (sum)"
  },
  "tokens": [
    {
      "name": "Answer",
      "type": "number",
      "title": { "en": "Answer" },
      "example": { "en": "5" }
    }
  ],
  "args": [
    {
      "name": "number_1",
      "type": "number",
      "placeholder": {
        "en": "Number 1",
        "nl": "Nummer 1",
        "de": "Nummer 1",
        "fr": "Numéro 1",
        "it": "Numero 1",
        "sv": "Nummer 1",
        "no": "Nummer 1",
        "es": "Numero 1",
        "da": "Nummer 1"
      },
      "min": 0,
      "max": 9999999999,
      "step": 1e-7
    },
    {
      "name": "number_2",
      "type": "number",
      "placeholder": {
        "en": "Number 2",
        "nl": "Nummer 2",
        "de": "Nummer 2",
        "fr": "Numéro 2",
        "it": "Numero 2",
        "sv": "Nummer 2",
        "no": "Nummer 2",
        "es": "Numero 2",
        "da": "Nummer 2"
      },
      "min": 0,
      "max": 9999999999,
      "step": 1e-7
    },
    {
      "type": "number",
      "name": "Answer"
    }
  ]
}

```

```auto
// register action ... runlisteners

    actions.forEach(({ id }) => {

      this.log('Adding runListener for action', id);

      this.homey.flow.getActionCard(id)

        .registerRunListener(async (args, state) => {

          const action = require(`./flow/actions/${id}`);

          const result = await action(timezone, tokens, args);

          return Promise.resolve(result);

        })

    });

```

---

<div class="post-metadata">

**Author:** ![Jens\_De\_Smet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jens_de_smet/32/33978_2.png) [@Jens\_De\_Smet](https://community.homey.app/u/Jens_De_Smet)\
**Post date:** [January 8, 2022, 3:46pm UTC](https://community.homey.app/t/stored-in-a-global-token/57981/10 "2022-01-08T15:46:07Z")

</div>

How should I solve that no new token is created but user can determine a token themselves.

See code above.

---

<div class="post-metadata">

**Author:** ![Adrian\_Rockall](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/adrian_rockall/32/13209_2.png) [@Adrian\_Rockall](https://community.homey.app/u/Adrian_Rockall)\
**Post date:** [January 8, 2022, 7:46pm UTC](https://community.homey.app/t/stored-in-a-global-token/57981/11 "2022-01-08T19:46:11Z")

</div>

Have you fixed the error of defining the const z variable twice?  
If you post sample code make sure it is free of such simple errors or we don’t know if that is simply the cause.

---

<div class="post-metadata">

**Author:** ![Jens\_De\_Smet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jens_de_smet/32/33978_2.png) [@Jens\_De\_Smet](https://community.homey.app/u/Jens_De_Smet)\
**Post date:** [January 9, 2022, 10:27am UTC](https://community.homey.app/t/stored-in-a-global-token/57981/12 "2022-01-09T10:27:03Z")

</div>

the problem is i want the user to be free to choose any variable(token) created in the homey flow interface and not a new one how do i do this ?

twice the same variable is not ok, I know that too, but how do you solve this problem?

---

<div class="post-metadata">

**Author:** ![Adrian\_Rockall](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/adrian_rockall/32/13209_2.png) [@Adrian\_Rockall](https://community.homey.app/u/Adrian_Rockall)\
**Post date:** [January 9, 2022, 10:29am UTC](https://community.homey.app/t/stored-in-a-global-token/57981/13 "2022-01-09T10:29:06Z")

</div>

> [@Jens\_De\_Smet](#):
>
> twice the same variable is not ok, I know that too, but how do you solve this problem?

Either give one of them a different name or define it with let instead of const.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 9, 2022, 10:30am UTC](https://community.homey.app/t/stored-in-a-global-token/57981/14 "2022-01-09T10:30:42Z")

</div>

> [@Jens\_De\_Smet](#):
>
> the problem is i want the user to be free to choose any variable(token) created in the homey flow interface and not a new one how do i do this ?

I’m pretty sure you can’t, at least not using the SDK (perhaps with the Web API but doubt it). Tokens (also global tokens) are tied to a specific app, and only that app can change their value.
