# Get the id value (from db) and add it to the output of a ui-form?

**URL:** <https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992>\
**Category:** Dashboard\
**Tags:** ui-widgets, dashboard-2\
**Created:** [8 November 2024 14:42 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992 "2024-11-08T14:42:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pepex7](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Pepex7](https://discourse.nodered.org/u/Pepex7)\
**Post date:** [8 November 2024 14:42 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/1 "2024-11-08T14:42:34Z")

</div>

I'm trying to do an update on a database record (postgres) with a ui-form (Dashboard 2), but I can't pass the id to the ui-form.

![Captura de Pantalla 2024-11-08 a la(s) 11.38.37](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f615abb969159c7449cc9a49484713c9c1bacbb5.png)

I don't get the id in the ui-form output so I can make the query and pass the id to modify.

---

<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:** [8 November 2024 14:53 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/2 "2024-11-08T14:53:45Z")

</div>

I'm afraid there is not enough information here to help you.

1. Show us the content of the function
2. Add a debug node to the DB output and show us what you get
3. Add a debug node to the Function output and show us what you get
4. Show us the ui-form fields

* * *

NOTE: post code as text using the `</>` code format button

---

<div class="post-metadata">

**Author:** ![Pepex7](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Pepex7](https://discourse.nodered.org/u/Pepex7)\
**Post date:** [8 November 2024 15:49 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/3 "2024-11-08T15:49:57Z")

</div>

thanks for your response.  
Query

```auto
SELECT * FROM alarma WHERE id_equipo=1 ORDER BY id DESC LIMIT 1;

```

function get id

```auto
var id
var getid

if (msg.payload[0].rst === false) {
    id = msg.payload[0].id;
    msg.getid = id
}
else {
    msg.getid = 1
}

return msg;

```

in debug 172, I get the id correctly.  
output of the ui\_form in debug 2573 (I have one field):

```auto
{"payload":{"1":"Siniestro"},"_client":{"socketId":"ZnmH_q-WKYeZpjXGAAIj","socketIp":"192.168.106.12"},"topic":"","_msgid":"45b2881273b0394b"}

```

I don't get an output with the field data and the id in the ui-form output to then do the query that updates the record in the db.

---

<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:** [8 November 2024 16:12 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/4 "2024-11-08T16:12:34Z")

</div>

The [dashboard docs for ui-form](https://dashboard.flowfuse.com/nodes/widgets/ui-form.html#populating-form-data) state:

> If you want to set defaults, or pre-fill values in your form, you can do so by passing a `msg.payload` value. This value should be an object, where each key represents the `key` of a form element, and the value represents the default value for that element.

However, I cannot tell you what you need to send to your form since you did not show the ui-form fields as requested:

> [@Steve-Mcl](#):
>
> 1. Show us the ui-form fields

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 November 2024 16:48 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/5 "2024-11-08T16:48:59Z")

</div>

I think possibly @Pepex7 does not want the id to appear on the form, he/she just wants to pass it through so that it is available after the form. Is that correct @Pepex7?

---

<div class="post-metadata">

**Author:** ![Pepex7](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Pepex7](https://discourse.nodered.org/u/Pepex7)\
**Post date:** [8 November 2024 16:51 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/6 "2024-11-08T16:51:38Z")

</div>

yes, to be able to update the correct record.

---

<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:** [8 November 2024 16:51 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/7 "2024-11-08T16:51:48Z")

</div>

Ah, that makes sense.

That is a good use case. Not sure "hidden fields" are supported however, it can be simulated with a join node or context.

---

<div class="post-metadata">

**Author:** ![Pepex7](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Pepex7](https://discourse.nodered.org/u/Pepex7)\
**Post date:** [8 November 2024 16:52 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/8 "2024-11-08T16:52:23Z")

</div>

![Captura de Pantalla 2024-11-08 a la(s) 13.50.07](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/2/c21ab2ca4a8d0dacc5b3d28dcb3a2a907cd530d2.png)  
ui-form have a one field.

---

<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:** [8 November 2024 16:58 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/9 "2024-11-08T16:58:46Z")

</div>

You could add a number field with the name `id` to the `ui-form` and use CSS to make it hidden. Then it will be sent in the payload when you click submit.

Note. you should probably give the field a better name than "1" so it is easier to populate vlia `msg.payload` 😉

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 November 2024 17:00 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/10 "2024-11-08T17:00:28Z")

</div>

If you set the id in `msg.topic` in the message passed to the form, and in the form config set Topic to `msg.topic` then that should be present in the form output.

---

<div class="post-metadata">

**Author:** ![Pepex7](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Pepex7](https://discourse.nodered.org/u/Pepex7)\
**Post date:** [8 November 2024 17:26 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/11 "2024-11-08T17:26:35Z")

</div>

> [@Steve-Mcl](#):
>
> You could add a number field with the name `id` to the `ui-form` and use CSS to make it hidden. Then it will be sent in the payload when you click submit.
> 
> Note. you should probably give the field a better name than "1" so it is easier to populate vlia `msg.payload` 😉

thank you..!!

---

<div class="post-metadata">

**Author:** ![Pepex7](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Pepex7](https://discourse.nodered.org/u/Pepex7)\
**Post date:** [8 November 2024 17:27 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/12 "2024-11-08T17:27:49Z")

</div>

I tried it like that but nothing happened because the output of the ui-form only sends the form.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 November 2024 17:41 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/13 "2024-11-08T17:41:48Z")

</div>

Show us what you are feeding into the form and what comes out.  
Also the form config please.

---

<div class="post-metadata">

**Author:** ![Pepex7](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Pepex7](https://discourse.nodered.org/u/Pepex7)\
**Post date:** [8 November 2024 17:46 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/14 "2024-11-08T17:46:45Z")

</div>

That's what comes out of the form

```auto
{"payload":{"1":"Siniestro"},"_client":{"socketId":"ZnmH_q-WKYeZpjXGAAIj","socketIp":"192.168.106.12"},"topic":"","_msgid":"45b2881273b0394b"}

```

Enter a msg.getid (with the correct id)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 November 2024 17:48 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/15 "2024-11-08T17:48:17Z")

</div>

Show us what you are feeding in and the form config (screenshot will do).

---

<div class="post-metadata">

**Author:** ![Pepex7](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Pepex7](https://discourse.nodered.org/u/Pepex7)\
**Post date:** [8 November 2024 17:58 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/16 "2024-11-08T17:58:22Z")

</div>

![Captura de Pantalla 2024-11-08 a la(s) 14.56.56](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/31b7a8d96c06d89cd5eca6e0c35db0f4da0def10.png)  
 ![Captura de Pantalla 2024-11-08 a la(s) 14.57.33](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/7/d7525ffc94f0c755d650b94a6e5cc6e649823a09.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 November 2024 18:05 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/17 "2024-11-08T18:05:53Z")

</div>

I suggested:

> [@Colin](#):
>
> set the id in `msg.topic` in the message passed to the form,

You haven't done that.

You have not shown the rest of the Form tab in the form config, where you need to:

> [@Colin](#):
>
> set Topic to `msg.topic`

---

<div class="post-metadata">

**Author:** ![Pepex7](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Pepex7](https://discourse.nodered.org/u/Pepex7)\
**Post date:** [8 November 2024 19:43 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/18 "2024-11-08T19:43:45Z")

</div>

![Captura de Pantalla 2024-11-08 a la(s) 16.40.39](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/d/2d0d02badbafc741f0b20edb4b67954a3428c08f.png)

Yes, I tried it from the function, passing the data through msg.getid.

---

<div class="post-metadata">

**Author:** ![Pepex7](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Pepex7](https://discourse.nodered.org/u/Pepex7)\
**Post date:** [8 November 2024 19:48 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/19 "2024-11-08T19:48:36Z")

</div>

> [@Steve-Mcl](#):
>
> use CSS to make it hidden.

Can I only put one class on the entire form? Not on a single field?

---

<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:** [8 November 2024 20:17 UTC](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992/20 "2024-11-08T20:17:04Z")

</div>

> [@Pepex7](#):
>
> Can I only put one class on the entire form? Not on a single field

Why would you need to?

Just use a suitably targeted css selector to single out the form(s) field(s) you wish to style

e.g.

```css
 /* adjust look of ui-form with class my-class-1 */
.my-class-1 [data-form='form-row-id'] {
   display: none; /* hide the field named id */
}
 /* adjust look of ui-form with class my-class-1 and my-class-2 */
div.my-class-1.my-class-2 {
   background-color: blue; /* color the main div */
}
/* etc etc */

```

[Next page](https://discourse.nodered.org/t/get-the-id-value-from-db-and-add-it-to-the-output-of-a-ui-form/92992.md?page=2)
