Server Action And Data Action

Difference Between Server Action And Data Action

Same same but different!

You must have heard this line on social media when you are scrolling through memes. Well, do you know this is also implied in many functions of OutSystems’ too? There are many elements in the OutSystems that you could feel are the same, but when you explore deeper, you will find there are many differences between the two elements you thought were the same.

In the last article, we will explore the difference between screen actions and client actions, which are considered the same in many parameters, but when we looked closely, there were significant differences between them, which defines the purpose of creating both of them. If you didn’t read that article, check out Difference between Screen Action and Client Action.

In this article, we will dive deeper into the difference between the server actions and data actions. 

Before we start the discussion, let’s structure the article so you know what things you will get in this article.

What is Data Action?

Data action is a server-side process that is used to fetch complex data from internal or external databases. In simple words, we can say that data actions are the action that works on the server side and are preferred when fetching the data from complex databases or when the data is being fetched from external sources like an external database or API.

What is Server Action?

When we talk about server actions, server actions are the logic run on the server side. In other words, we can say that all the logic that is written inside the server action flow will always be executed on the server side, and after the flow is executed, the response will be shown on the client side, like the changes in the data or records if needed, etc.

Difference Between Server Action And Data Action

Scope

Before we talk about the scope of both actions, let’s understand what scope is. The scope of an action is the places where it can be used, like there are elements whose scope is only inside the same screen, while there are elements that can be used anywhere inside the module.

So, if we start with data action, then the scope of the data action is limited to the respective screen/block in which it is created. In simple language, the screen/block inside which the data action is created, the data action’s scope is that screen/block only; it can’t be used in any other screen.

But if we talk about the server action, then the scope of the server action is everywhere; it can be used inside the different screens in the same module, or it can be in different modules too.

So now we can say that the scope of server action is way wider than data actions.

Reusability

The reusability is the ability to use the respective element more than once. Which means if an element can be used multiple times for the same or different purposes, then that element is reusable.

Data action is not reusable as we discussed before; that’s not possible for the data action to be used in a different screen or block than it was created.

On the other hand, server action can be used multiple times inside a module can also be used inside different modules, until and unless the server action’s public property is set to “Yes”.

So, if you are creating an action that you think will be used multiple times, then use a server action rather than a data action.

Allowed Parameter

There are three types of parameters in OutSystems: input parameters, output parameters and local variables. Different actions are allowed to use different parameters. Let’s understand how data actions and server actions are different when it comes to parameters.

Inside the data action, you can create a local variable, as well as an output parameter, but an input parameter is not allowed to be created inside the data action. Other than this, there is one more noticeable thing in data action, that it is mandatory for data action to have at least one output parameter, which is used somewhere in the screen.

When we talk about server action, there is no such restriction on the basis of parameters in server action. Server action can have all three parameters or none if there is no need for it.

Asynchronous

In OutSystems actions are executed in two ways, synchronous and asynchronous. When actions are executed synchronously then actions execute in serial form or one after the other, while when actions are executed asynchronously then they are executed at the same time. Which means if there are three processes which is asynchronous, then they will start at the same time and will be executing parallelly. Let’s understand the difference between data action and server action executing synchronously and asynchronously.

Data action executes asynchronously, which means if there are three data actions on a screen, then they will be executed at the same time together.

On the other hand, server action follows the rule of synchronicity. Which means that if there are three server actions, then the first server action will execute first and the second server action will not start it’s execution until the first server action’s flow is executed, and same will happen with third server action, until the second server action’s flow won’t be completed, third server action cannot start.

Implementation Restrictions

There are some restrictions while implementing the actions, like in the previous article we discussed the restriction of implementation of screen action and client action, similarly, there are implementation restrictions of data action and server actions too. Let’s dive deeper.

Data action is restricted to be used anywhere other than the screen. Which means that a server action can’t have a data action.

But on the other hand, server action is accessible inside the data action and can be executed inside the data action without any warning or error.

Conclusion

After discussing all the important differences between server action and data action, we can say that both of them work best on their respective use cases, like if you wanted to that the actions needs to be executed during the screen initialization or many server-side processes needs to be execute together then you should choose data action.

But if you wanted an action that you can use multiple times in different screens, blocks. And modules, you should opt for server action.

I hope this action helped you to understand the difference between server action and data action, shedding your doubt.

And if you want a knowledgeable article, then do subscribe to our newsletter, so you can read our latest article.

Happy coding!

Facebook
Pinterest
Twitter
LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *