Shared or "Flexible" Client/Server Actions
217
Views
4
Comments
New
Service Studio

Hi everyone,

I am currently working on some client/server side validations, and noticed that the Client/Server separation often requires a duplication of code (validations in client side and validations in server side). Because of this, I thought of the idea of potentially having some "Flexible", "Elementary" or "Basic" Action types that could be reused on both Client and Server Actions, considering that OutSystems uses its own set of basic data types that are shared between client and server side logic.

The constraint of these types of actions would be:

  1. When they are called within a Client Action, they run as Client Action (client-side logic, runs in the browser); when they are called within a Server Action, they run as a Server Action (server-side logic, runs in the server).
  2. They cannot contain calls to Client or Server Actions. They can only call other "Flexible" actions in their flow and basic operations that are already available both in Client/Server Actions, such as: If, Assign, For Each, etc.
  3. They would generally be used for primitive operations: basic arithmetic and logic operators, and built in List-related actions, restricting any functionality that might make the "Flexible" behavior technically impossible.

I understand that Server Actions can be used normally within Client Actions, however (as far as I am aware), they require a server call and therefore cannot be used as validations that run exclusively in the browser.

In general, these could be useful wherever a shared foundation codebase between client-side and server-side logic would be useful, such that it could also be extended on both sides independently. The first scenario I can think about is client and server side validations, but I am sure there are similar scenarios where such a functionality would be useful to avoid code duplication.

Totally agree.

Merged this idea with 'Universal Functions - Client and Server at the same time' (created on 05 Dec 2023 02:00:49 by Denys Bondarenko)

Imagine I have a function that performs some complex computations based on its inputs, or has some extensive logic that deals with static entities. It does not make server calls. Its flow could probably fit inside an expression.

If I encapsulate this logic in a server function, I will have to create a client-side clone if I want to use it somewhere on a screen or block. And vice versa.

My idea is to enable the creation of "universal functions". Think of them as client functions that can't make server calls, and are usable on the server-side. This is an intuitive way to reduce code duplication.

Hi Denys,

Nice idea, i am 99% sure the idea already exists on the Ideas page, buso I will merge it.

Regards,

Daniel