# Load value into function

**URL:** <https://discourse.nodered.org/t/load-value-into-function/60489>\
**Category:** General\
**Created:** [29 March 2022 11:28 UTC](https://discourse.nodered.org/t/load-value-into-function/60489 "2022-03-29T11:28:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pikny](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Pikny](https://discourse.nodered.org/u/Pikny)\
**Post date:** [29 March 2022 11:28 UTC](https://discourse.nodered.org/t/load-value-into-function/60489/1 "2022-03-29T11:28:20Z")

</div>

Hi!  
I would like to write a function, when initiated by "PLC start mission", will take the value from "robot\_id" and enter it in the appropriate place in the function. Unfortunately, he keeps throwing me an error. Anyone tell me how to correctly load a value into my function?

![Screenshot_1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cfc8e923fb5cc0b45f713075cfd0df07397bec8f.png)

 ![Screenshot_2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/5/e5cd97e54da73f1e2b41584084b735102f9dcd52.png)

---

<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:** [29 March 2022 11:58 UTC](https://discourse.nodered.org/t/load-value-into-function/60489/2 "2022-03-29T11:58:02Z")

</div>

Hi @Pikny.

Can you use debug nodes after your Switch and robot\_id nodes to show us what's arriving at the Function?

It would be good to see the actual error message you get too.

---

<div class="post-metadata">

**Author:** ![fugit185](https://avatars.discourse-cdn.com/v4/letter/f/a87d85/32.png) [@fugit185](https://discourse.nodered.org/u/fugit185)\
**Post date:** [29 March 2022 12:46 UTC](https://discourse.nodered.org/t/load-value-into-function/60489/3 "2022-03-29T12:46:44Z")

</div>

Hello, if you want to get help, please, answer questions from forum...

---

<div class="post-metadata">

**Author:** ![Pikny](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Pikny](https://discourse.nodered.org/u/Pikny)\
**Post date:** [5 April 2022 11:54 UTC](https://discourse.nodered.org/t/load-value-into-function/60489/4 "2022-04-05T11:54:50Z")

</div>

Hi jbudd.

I apologize for the late response.  
I improved my flow.

All the time I have a problem with load number of robot\_id in the function node. Robot\_id is "undefined".  
How I should define this variable correctly?

I will be grateful for your tips and help.

 ![Screenshot_5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/43c1b5530ce0fcb5438da468d8af4b1ae892fa96.png)  
 ![Screenshot_6](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/b/2bd6d21b759794126ec750bf2c42162105025c9b.png)

---

<div class="post-metadata">

**Author:** ![Pikny](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Pikny](https://discourse.nodered.org/u/Pikny)\
**Post date:** [5 April 2022 11:57 UTC](https://discourse.nodered.org/t/load-value-into-function/60489/5 "2022-04-05T11:57:10Z")

</div>

This is example value model from documentation:

![Screenshot_7](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/949fe76046f45db63f371bf5689d41e62ff6dc03.png)

and the values, which I would like to use:

![Screenshot_8](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/95ea1b2b21688680fa748518543987f80ec733a2.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:** [5 April 2022 12:36 UTC](https://discourse.nodered.org/t/load-value-into-function/60489/6 "2022-04-05T12:36:10Z")

</div>

Your robot id is in `msg.payload` not `msg.payload.robot_id_int`

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a4772fe8d4ee70d65c4e8cef2b5cd0f8021c5ded.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/2/42463dc48e92fcfebbfaf48eaacb8aa809a6a70a.png)

* * *

Additionally, looking at your flow, I suspect you think these 2 messages will arrive into the function at the same time. **They will not**! This is a fundamental point to understand if you are to be proficient with node-red.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/0/a0c2f444b937b7f90dd8aed163992fc612143397.png)

For this you would need to store the robot ID in context or use a join node.

* * *

to avoid mistakes like these, it would be worth spending a little time learning the basics...

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![Pikny](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Pikny](https://discourse.nodered.org/u/Pikny)\
**Post date:** [25 April 2022 05:26 UTC](https://discourse.nodered.org/t/load-value-into-function/60489/7 "2022-04-25T05:26:36Z")

</div>

Thank you for your activity.  
I watched this playlist and I understood some problematic topics.  
I solved my problem.

Best regards!

---

<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:** [24 June 2022 05:27 UTC](https://discourse.nodered.org/t/load-value-into-function/60489/8 "2022-06-24T05:27:31Z")

</div>

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