Manipulate form data before passing them to a query

Problem

I don't understand how to edit the form submission results before adding the data to the query.

Situation

I have a form with several fields. After submission, I need to do a relatively complex manipulation that requires writing a couple of functions. After that, I want to pass the manipulated object to a query that will use the obj data to write to a SQL db.

What I tried

I tried creating a transformer and passing the returned value (of the transformer) as an object to the query that creates the data in the db but it doesn't work.

For what I read in the docs, transformers should be used to manipulate the results of a query, after and not before. That's probably why it didn't work, but I don't understand how I can write a script to edit the form submission results before adding the data to the query.

Can anyone point me in the right direction?

Thanks

@Giac
Try using additionalScope

https://docs.retool.com/docs/scripting-retool#triggering-a-query

1 Like

Thanks for the tip @ScottR, I'll give it a try

How can we modify form data on run time? e.g. I want to change updated by field of form on runtime with {{current_user.full_name}}.

Hi @Vivek_Kumar

Could you set the default value to be the current user data? If not, what about having a Javascript query that runs on page load & sets the field to be populated with the current user data?

the default value is okay but I'm setting this field value to the actual value(i.e. previously updatedBy) and it's working fine. but I want to update this textInput value with current_user.fullName before submitting the form, how can we do that?

Hi @Vivek_Kumar

Can you use the .setValue approach? If you want it to happen right before form submission, you could trigger a .setValue query on form submission & then chain your actual form submission query on success

Tess, many thanks. The setValue() approach worked a treat for me.

1 Like