How do i do to create a CreateOrUpdateResourceWrapper?

Hi, i am having a problem with the mobile developing curse, he asks for me to put a CreateOrUpdateResourceWrapper in the loggic scope but it dont exist in my app, and he dont teach me how to create this one, i have just the createToDoWrapper and UpdateToDoWrapper, thanks in advance 


Hi Emanuel,

The wrapper here is just a Server Action created in the same module as the Entity, that will be used instead of the Entity Action.

So, in this case, it is asking you to create the referred Action and use it in the place of the CreateOrUpdateResource entity action.

You open the data module, add a new Server Action (with the name asked in the exercise), create the input parameter (Resource record data type), and an output parameter (Resource Identifier), and create the logic inside it to create or update a record using the input parameter, and return the new/update record identifier (id).

Than you make it Public, and set the entity to be Expose Read Only YES.

Publish, refresh the dependences in the consumer module and reference the new Server Action and fix the errors (the places where you were using the Entity Action that now is not available, replacing it by the new Server Action).

The idea is to have a wrapper that you can use to guarantee no bad data is inserted in the database and that anyone that wants to inser/update data in this entity will have to use your Action.

Cheers

P.S. In the case of the exercise, instead of a record it is asking you for specific input parameters that you will have to use.

Hi Eduardo,

Thank you for the prompt response on the query. Can you please elaborate your answer with screenshots if possible?




Hi Mahammad,


See below action taken from Justin's Application Framework

You know we have the Entity actions like Create, CreateUpdate, etc. You then create Server action called EntityWrappers to 'wrap' these entity actions. As we know, these entity actions just accepts whatever you pass them and if the data you are passing is incorrect, it will throw that database error. You do these wrapper with the goal to do validations before calling the entity action itself. You can also introduce business specific logic before or after doing the entity action, like say, when I create the product, I need to also insert this product to the inventory table and set the product's stock amount to 0. Or as in the above example, write an audit log that the entity was successfully created.

Cheers,

JC

Eduardo Jauch wrote:

Hi Emanuel,

The wrapper here is just a Server Action created in the same module as the Entity, that will be used instead of the Entity Action.

So, in this case, it is asking you to create the referred Action and use it in the place of the CreateOrUpdateResource entity action.

You open the data module, add a new Server Action (with the name asked in the exercise), create the input parameter (Resource record data type), and an output parameter (Resource Identifier), and create the logic inside it to create or update a record using the input parameter, and return the new/update record identifier (id).

Than you make it Public, and set the entity to be Expose Read Only YES.

Publish, refresh the dependences in the consumer module and reference the new Server Action and fix the errors (the places where you were using the Entity Action that now is not available, replacing it by the new Server Action).

The idea is to have a wrapper that you can use to guarantee no bad data is inserted in the database and that anyone that wants to inser/update data in this entity will have to use your Action.

Cheers

P.S. In the case of the exercise, instead of a record it is asking you for specific input parameters that you will have to use.

Hi Eduardo, I know this is an old post but I've come across this issue where I need to call the server action "CreateOrUpdateResourceWrapper" for the ToDo application. Please can you see the screenshot and advise where I am going wrong? Thanks in advance :) 



Juan Carlos Elorde wrote:

Hi Mahammad,


See below action taken from Justin's Application Framework

You know we have the Entity actions like Create, CreateUpdate, etc. You then create Server action called EntityWrappers to 'wrap' these entity actions. As we know, these entity actions just accepts whatever you pass them and if the data you are passing is incorrect, it will throw that database error. You do these wrapper with the goal to do validations before calling the entity action itself. You can also introduce business specific logic before or after doing the entity action, like say, when I create the product, I need to also insert this product to the inventory table and set the product's stock amount to 0. Or as in the above example, write an audit log that the entity was successfully created.

Cheers,

JC


Thanks JC

Hello Tamanna, 

There is nothing 'wrong'. 

But you have to implement the code in the server action that will take the input data, save in the entity (using the entity actions) and return the id created through the output parameter. 

Cheers