Changing an entity's variable through the one-to-many relationship

Good Morning,

I create a system that has two entities Projeto and Tarefa that are related in which a Projeto can have several Tarefas.

So I'm creating a condition that if the status of a Projeto is changed to "canceled" all Tarefas with a status other than completed should be automatically canceled.


I present here an image of what I tried to do but it is not working, I have an if that checks if the status is equal to canceled and if there is a query that fetches me all the Tarefas of that Projeto with the status other than completed and then through of an assign I'm trying to change their status to "canceled".




Hi, friend.

Are you using a for each looping to set ALL Tarefas to "canceled" status? Using only the assign, you'll change only the first item on the list (the current value).

The way I see, you must use an for each to iterate, then assing canceled to status and finally update the value in database. 

You can do that through list comands or running and SQL to update all records (best optimized) as well.


Best regards.

Hi Diana,


You have a couple of options in this situatuon.

1. You can create an SQL. Everytime a Projeto is cancelled, you run that update SQL thal will be responsible for changing the status of all Tarefas. 

2. You can use that aggregate that shows you all tarefas that have a status different that Completed and have a for each to go through that same list. In each iteration you change the status of the current record with the assignment and then call a CRUD action to save your information in the DB.


Best Regards,


João Delgado

João Delgado wrote:

Hi Diana,


You have a couple of options in this situatuon.

1. You can create an SQL. Everytime a Projeto is cancelled, you run that update SQL thal will be responsible for changing the status of all Tarefas. 

2. You can use that aggregate that shows you all tarefas that have a status different that Completed and have a for each to go through that same list. In each iteration you change the status of the current record with the assignment and then call a CRUD action to save your information in the DB.


Best Regards,


João Delgado

Try to do the second way you indicate but updateTarefa does not accept or identifies as you want to send errors is not working. 

What am I doing wrong?

Solution

Diana,


Your Cycle is starting to the wrong way. Do a right click in the for each and choose swap connectors. This will make your cycle arrow switch.

What are you putting in the CRUD action? You should use a createorupdate and put the record that you are iterating and not the Identifier.


I can show you the following example:



Also, take some time to read about CRUD Wrappers ( https://medium.com/@jmjames/outsystems-crud-wrapper-basics-e9a577a3e044 ). As you progress in your outsystems journey they will be very handy for you.


Best regards,


João Delgado




Solution