# Variable global

**URL:** <https://discourse.nodered.org/t/variable-global/69662>\
**Category:** General\
**Created:** [27 October 2022 08:41 UTC](https://discourse.nodered.org/t/variable-global/69662 "2022-10-27T08:41:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giacomo23](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@Giacomo23](https://discourse.nodered.org/u/Giacomo23)\
**Post date:** [27 October 2022 08:41 UTC](https://discourse.nodered.org/t/variable-global/69662/1 "2022-10-27T08:41:48Z")

</div>

hi everyone, I'm trying to create a global variable but it is registered as an object and not as a value, what can I do?  
Example I would like the output of the "file\_iniziale" variable to be the same format as the "file" variable  
 ![Cattura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/43b48929b2e8dc60536b52e3a73885b595bb4597.png)

thanks for all

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 October 2022 08:46 UTC](https://discourse.nodered.org/t/variable-global/69662/2 "2022-10-27T08:46:20Z")

</div>

> [@Giacomo23](#):
>
> I'm trying to create a global variable but it is registered as an object and not as a value, what can I do?

Dont write an object to it?

show us how you set this global variable & we will show you how to get the internal `file` value.

---

<div class="post-metadata">

**Author:** ![Giacomo23](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@Giacomo23](https://discourse.nodered.org/u/Giacomo23)\
**Post date:** [27 October 2022 08:53 UTC](https://discourse.nodered.org/t/variable-global/69662/3 "2022-10-27T08:53:29Z")

</div>

![Cattura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f323cf43e0bfbfef265af24fe89759850c416cca.png)  
 ![Cattura1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/6/262511cb1a6c62e30dbe5b67e0d8dc880a0c00e9.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 October 2022 08:58 UTC](https://discourse.nodered.org/t/variable-global/69662/4 "2022-10-27T08:58:57Z")

</div>

Please post these as code/text not images and I will show you exactly how to correct this.

(I cannot edit text in an image & and I don't feel like rewriting it everything 😉)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [27 October 2022 09:22 UTC](https://discourse.nodered.org/t/variable-global/69662/5 "2022-10-27T09:22:29Z")

</div>

What are you trying to do in function 42?

Can you replace all this confusing code with this?  
`global.set("file_iniziale", msg.payload)`

Which should result in global.file\_iniziale == "change" (or whatever is in msg.payload)

---

<div class="post-metadata">

**Author:** ![Giacomo23](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@Giacomo23](https://discourse.nodered.org/u/Giacomo23)\
**Post date:** [27 October 2022 09:34 UTC](https://discourse.nodered.org/t/variable-global/69662/6 "2022-10-27T09:34:12Z")

</div>

sorry I'm stupid I solved the problem by removing the function of the first image  
"  
var file {}  
{  
file: msg.payload  
}  
"  
thanks for all

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 November 2022 09:34 UTC](https://discourse.nodered.org/t/variable-global/69662/7 "2022-11-10T09:34:51Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
