Approach for createOrUpdate server action

Hi,


I have a server action createOrUpdateSection. This server action receives an input parameter "Section" of type Section entity and 3 output parameters (FormInvalid, FormInvalidMsg and CreatedOrUpdatedMsg).


In this server actions there are some validations if the validation fails the FormInvalid becoems true and the FormInvalidMsg stores the respective invalid form message. If there are no validaiton errors the CreateOrUpdate entity action is called with the input parameter "Section" and then the "CreatedOrUpdatedMsg" becomes with a text like "Section created".


My doubt if there is a better approach for this simpele operations, specifically about which output parameters should exist, if the invalid fields should be also returned, etc.

Solution

I think it is better separate things, like handle validations and their related messages on a Screen Action. The Server Action should only concerns about the data that it is using and throwing exceptions when the input parameter is wrong, so the caller can handle it appropriatelly.

It will improve maintainability and flexibility of your application, because you will be able to use the Server Action in other parts without having to create conditions to support another clients. Furthermore, you will be able to edit messages and validations without impact on the Action Server.

Champion

Hi Jake,

Hope you are doing well.

I'm not sure wrap validation to a server action is a good idea.

The validation mostly  for input form, so simple approach is like below.

If I misunderstand you, I'm sorry.

Kind regards,

Hi Jake,

A nice approuch would be set the Sever Action Function attribute to Yes and then return a value that informs whether the Section was created or not (as a function, a server action can have only one output parameter).

Hope it helps,

Best regards.

Thanks, and return also an output parameter with the invalid fields and then on the save screen action use that is not a good approach? Like return all the invalid fields with the respective messages as an output parameter I dont know if with a text output parameter or list, do you know which is better? Thanks!

Solution

I think it is better separate things, like handle validations and their related messages on a Screen Action. The Server Action should only concerns about the data that it is using and throwing exceptions when the input parameter is wrong, so the caller can handle it appropriatelly.

It will improve maintainability and flexibility of your application, because you will be able to use the Server Action in other parts without having to create conditions to support another clients. Furthermore, you will be able to edit messages and validations without impact on the Action Server.

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