# Problem with instance.data.variable not working

**URL:** <https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089>\
**Category:** Plugin builders\
**Created:** [April 7, 2021, 12:47am UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089 "2021-04-07T00:47:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cangrimen](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@cangrimen](https://forum.bubble.io/u/cangrimen)\
**Post date:** [April 7, 2021, 12:47am UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089/1 "2021-04-07T00:47:23Z")

</div>

Hello.

I’m really driving crazy with this problem.

My update has properties.xxx (from the element fields).  
Everything ok.

I want to pass some variables to my element action, so I did this:

```
instance.data.source = properties.source;
instance.data.color = properties.getcolor;
console.log(instance.data.source);
console.log(instance.data.color);

```

result:  
`https://xx.com`  
`#000FFF`

Easy right?

Ok now in my element action code:

```
var source = instance.data.source;
var color = instance.data.color;

console.log(source);
console.log(color);

```

result:  
`undefined`  
`undefined`

What i’m missing ??

---

<div class="post-metadata">

**Author:** ![jared.gibb](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/jared.gibb/32/123329_2.png) [@jared.gibb](https://forum.bubble.io/u/jared.gibb)\
**Post date:** [April 7, 2021, 12:50am UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089/2 "2021-04-07T00:50:40Z")

</div>

Are you passing between elements in the same plugin?

Or are you trying to pass data to/from a workflow action from an element action?

Something like that?

I do this ^^^^^ passing of data all the time

---

<div class="post-metadata">

**Author:** ![cangrimen](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@cangrimen](https://forum.bubble.io/u/cangrimen)\
**Post date:** [April 7, 2021, 1:08am UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089/3 "2021-04-07T01:08:41Z")

</div>

Hi @jared.gibb

Yes it’s in the same plugin. Same element (My plugin only has one element).

As said, im trying to pass data from update to element action.

But for some reason is not working…

[![](https://i.imgur.com/JvezhUp.png) ](https://i.imgur.com/JvezhUp.png)

[![](https://i.imgur.com/7ySV2j3.png) ](https://i.imgur.com/7ySV2j3.png)

---

<div class="post-metadata">

**Author:** ![jared.gibb](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/jared.gibb/32/123329_2.png) [@jared.gibb](https://forum.bubble.io/u/jared.gibb)\
**Post date:** [April 7, 2021, 1:18am UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089/4 "2021-04-07T01:18:53Z")

</div>

It feels like the data aren’t getting where you think they should be. In update, keep the console log. Only after you see it fire in update, try to run your action and see the result. Remove all code except for the passing of data and logging to check if it’s there.

If that doesn’t work the issue would likely lie in the update code and something blocking those data from passing.

---

<div class="post-metadata">

**Author:** ![jared.gibb](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/jared.gibb/32/123329_2.png) [@jared.gibb](https://forum.bubble.io/u/jared.gibb)\
**Post date:** [April 7, 2021, 12:12pm UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089/5 "2021-04-07T12:12:03Z")

</div>

Did you get that sorted out?

---

<div class="post-metadata">

**Author:** ![lstk.kb](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/lstk.kb/32/163042_2.png) [@lstk.kb](https://forum.bubble.io/u/lstk.kb)\
**Post date:** [August 24, 2021, 7:50am UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089/6 "2021-08-24T07:50:48Z")

</div>

I have the same problem

 ![24-08-2021 10-43-56](https://us1.discourse-cdn.com/bubble/original/3X/2/f/2f4ebcc39c5cc3d02626c3f4cb2e2a6622fcb423.jpeg)  
 ![24-08-2021 10-44-35](https://us1.discourse-cdn.com/bubble/original/3X/b/3/b338e30f4722b853e9f3e531b528b4f894e59689.jpeg)  
 ![24-08-2021 10-45-24](https://us1.discourse-cdn.com/bubble/original/3X/9/2/921e79a943601f3ed499c5cea1dde36d04d10079.jpeg)

 ![24-08-2021 10-50-09](https://us1.discourse-cdn.com/bubble/original/3X/4/9/4911ecd4532fddc39775d0591fd65835d10c8347.jpeg)

---

<div class="post-metadata">

**Author:** ![exception-rambler](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/exception-rambler/32/152704_2.png) [@exception-rambler](https://forum.bubble.io/u/exception-rambler)\
**Post date:** [August 24, 2021, 8:58am UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089/7 "2021-08-24T08:58:10Z")

</div>

The only real possibility is that the `Action` is running prior to the Update function, or prior to `Update` running once the data you are pulling in via `Properties` is available to it.

You could bring the `Properties` that you need directly in via the `Action`, instead of relying on `Update`? There may be a reason that you are not doing that…

If you _have_ to use `Update` for some reason then you could do something like:

1. Set `instance.data.init = false` In your `Initialize` function
2. Within `Update` Check for values within your `Properties` object whilst `instance.data.init = false`
3. Once you find values then set `instance.data.init` to `true` And trigger an event (`instance.triggerEvent()`) that then, via a workflow, calls your Action.

I often use this kind of switch to better manage how plugins initialise because the sequence of operation during page load is unpredictable and `Update` will often run several times during one page load.

---

<div class="post-metadata">

**Author:** ![lstk.kb](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/lstk.kb/32/163042_2.png) [@lstk.kb](https://forum.bubble.io/u/lstk.kb)\
**Post date:** [August 24, 2021, 9:32am UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089/8 "2021-08-24T09:32:40Z")

</div>

Thanks! You’re right.

 ![24-08-2021 12-23-49](https://us1.discourse-cdn.com/bubble/original/3X/9/d/9d0e5a8546d3472cc41a8a977236567f7003f65a.jpeg)

After setting the 1s timeout in action, everything worked  
 ![24-08-2021 12-27-53](https://us1.discourse-cdn.com/bubble/original/3X/f/a/fa3a4a600aa14f0ba02258ac3b07b3790842d220.jpeg)

I am planning to create my own global object and store the necessary variables in it.

---

<div class="post-metadata">

**Author:** ![yigal](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/yigal/32/36259_2.png) [@yigal](https://forum.bubble.io/u/yigal)\
**Post date:** [September 20, 2022, 8:56pm UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089/9 "2022-09-20T20:56:44Z")

</div>

Is that the only solution?

---

<div class="post-metadata">

**Author:** ![exception-rambler](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/exception-rambler/32/152704_2.png) [@exception-rambler](https://forum.bubble.io/u/exception-rambler)\
**Post date:** [September 22, 2022, 4:34pm UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089/10 "2022-09-22T16:34:51Z")

</div>

I think you’re solving for the following:

- `initialize` will always run before `update` - neither will run when the element is hidden
- `actions` may run before `update` has had the opportunity to, therefore you can’t rely on `update` to bring in data that your `actions` may rely on.
- `actions` won’t run before `initialize` has run and can therefore reference data and methods that were defined inside `initialize`, as long as your element is not hidden.
- but if it is hidden, `actions` can still run but you can no longer rely on data or methods that were defined within `initialize`

So you’re writing your code to reliably work within those constraints - I guess anything that does that can be considered your solution.

---

<div class="post-metadata">

**Author:** ![yigal](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/yigal/32/36259_2.png) [@yigal](https://forum.bubble.io/u/yigal)\
**Post date:** [September 23, 2022, 12:32pm UTC](https://forum.bubble.io/t/problem-with-instance-data-variable-not-working/145089/11 "2022-09-23T12:32:05Z")

</div>

Thanks Edward,  
You pointed me in the right direction.  
The element was shown in the editor, but still the ‘initialize’ function wasn’t triggered because I didn’t mark this option:  
“Support standard visible property”  
If you don’t enable it, the initialize function never runs.
