Flow to save data from a client action to a server action
Discussion

Hello there,

I have a question about the best way to work at reactive.

In any of my screens or webblocks I end up having a save button, which calls a client action.

Obviously I need to end up calling a server action that saves whatever it is in the database, but I can't logically put it inside the client action.

Would I have to create a action "fetch data form other resources" with the server action "saveData" and do a refresh from the client action? What about all the data that I need to collect from the screen? I have to store them in local variables of the page, making a set from the client and then grabbing them in the serveraction?

It seemed to me that the fetch data from other resources actions were just getting data and not for this ...

Hi CrisSanz,

what do you mean when you say I can't logically put it inside the client action.

You can drag a server action (or even an entityAction, but that's not recommended) to your client action's flow.  Whatever you want to pass on from the client would have to be input parameters in your server action.

This is most definitely not something to do with fetch !

Dorine

I meant that it is not recommended to put a server action in a client action.

Ok, so that's what I thought, you have to use the "Fetch data from other resources" actions to create server actions that save in the database, not just to get data


Hi CrisSanz,

I have never come across such a recommendation.  You are maybe confusing this with the recommendation to try not to have several server action calls inside one client action, but group all the work that needs to be done in a single server action.

And again, NO, do not use "Fetch..." action for that.


EDIT : TIP : if you drag an entity to a flow, you can look at the scaffolded screens to get a starter idea of how to do things.

Hi CrisSanz,

All the data collected on the web page will be stored in local variables. When user clicks Save button, it will obviously invoke a client action. You can perform the necessary client side validations there and once done, you need to put a server action which saves the data to entities. The server action has input parameters, where you will map the local variables to relevant input variables. 

It is to be noted that the best practice is to have only one server action in a client action so that only one round trip of web request is performed between the browser and the server during the Save.

Hope this clarifies.

Thanks for the answers, I thought you couldn't put server actions into client actions because it would penalize performance.

I did not know that they could be grouped into a single server action and I did not know of problems

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.