How to update JsonB data using a modal

Hello everyone,

I'm having trouble updating data in a JSONB field from my postgres database, and I could really use some help.

Here's my setup:

  1. Field Configuration: I've set up my database field type as JsonB, and the data type as Array, as shown in the image below.

  2. Data Structure: My data is organized like this:

[{"processo":"861427/2010","paeEntregue":null,"rfpEntregue":null,"requerimentoDePesquisa":null,"licencaDeOperacaoObtida":"2023-10-23","pedidoDeConcessaoDeLavra":null,"requerimentoDeLavraAprovado":"2020-05-18","validadeDaLicencaDeOperacao":"2028-10-18"},{"processo":"861428/2010","paeEntregue":null,"rfpEntregue":null,"requerimentoDePesquisa":null,"licencaDeOperacaoObtida":"2023-10-23","pedidoDeConcessaoDeLavra":null,"requerimentoDeLavraAprovado":"2020-02-21","validadeDaLicencaDeOperacao":"2028-10-18"},{"processo":"861430/2010","paeEntregue":null,"rfpEntregue":null,"requerimentoDePesquisa":null,"licencaDeOperacaoObtida":"2023-10-23","pedidoDeConcessaoDeLavra":null,"requerimentoDeLavraAprovado":"2020-02-21","validadeDaLicencaDeOperacao":"2028-10-18"},{"processo":"861431/2010","paeEntregue":null,"rfpEntregue":null,"requerimentoDePesquisa":null,"licencaDeOperacaoObtida":null,"pedidoDeConcessaoDeLavra":null,"requerimentoDeLavraAprovado":"2020-02-21","validadeDaLicencaDeOperacao":null},{"processo":"861694/2010","paeEntregue":null,"rfpEntregue":null,"requerimentoDePesquisa":null,"licencaDeOperacaoObtida":null,"pedidoDeConcessaoDeLavra":"2016-04-26","requerimentoDeLavraAprovado":"2020-11-27","validadeDaLicencaDeOperacao":null}]
  1. Workflow: I created a workflow for loading the data:

  2. Server Connect: This workflow is used to populate a table with the data from my database.

This allows me to display all the relevant information on the frontend:

The problem I'm facing now is updating this information using a modal form. I understand I probably need a workflow for this, but I'm not sure how to correctly send the updated data to the backend for updating the JSONB field.

Could anyone provide some guidance or a step-by-step example on how to set up this workflow to handle updates? Any help would be greatly appreciated!

Add hidden input field to the form, to indicate which index/row is the form referring to (e.g. in the current example, index 0)

You could use a Repeat step to iterate the array you want to replace, with a Condition if $index == $_POST.index then you Set Value each value from $_POST (each form field). The result of that Repeat is the new array that you need to Database Update in the JsonB column

I don't have time to give a step-by-step, but that should point you in the right direction :slight_smile:

1 Like

Thank you for the response!

Just to clarify, when you mention the "Repeat step", are you referring to the Repeat that is available in the Server Action Workflows?

Yes, it should iterate on the array coming from the database query

1 Like