Button to update all records of a column in the table for Boolean = false ...

Hello everyone,


As the subject itself says, I have a screen and in the action ZERAR Tarefas (button), I want to run an update on all rows and a column that contains the value true for false. I've tried with SQL and other ways but I can not because I'm new to Outsystems and I'm still walking step by step.

It follows below for a better understanding ...

Solution

So 

1- You will need a server action to clear all to false, to "Zerar Tarefas"

2- On the server action you will have a for each an assign to pass to false the attributes that are true and if not it continues for each

3- And that's a way to clear the tasks of the data that is being displayed on the screen for those records

If you want to clear all the tasks in the database, really all you must do is almost the same, but in this case, you will not share the aggregate, there will be a different Server action that has the aggregate without max records and it will do a for each passing the boolean attribute that is true to false.

1



Give it a try, and let me know

Kind regards,

Márcio Carvalho

clearAllData.oml

mvp_badge
MVP
Solution


Hello again!

Your query is correct, you just can't use Test to actually make the update. Also, an update does not return any rows, which is why it says no rows were returned.

Regarding your error, you need to remove the input parameter to the query (GerTarDia) as it is not used in the query.

Hope that helps!

Hello Nova Bella, so, to do that, you just need to pick the list and put the attribute to false using a for each.

Can you share an OML of that?

If not, I will try to deliver an example

Kind regards,

Márcio

Solution

So 

1- You will need a server action to clear all to false, to "Zerar Tarefas"

2- On the server action you will have a for each an assign to pass to false the attributes that are true and if not it continues for each

3- And that's a way to clear the tasks of the data that is being displayed on the screen for those records

If you want to clear all the tasks in the database, really all you must do is almost the same, but in this case, you will not share the aggregate, there will be a different Server action that has the aggregate without max records and it will do a for each passing the boolean attribute that is true to false.

1



Give it a try, and let me know

Kind regards,

Márcio Carvalho

clearAllData.oml

mvp_badge
MVP

Hey Márcio Carvalho,

For bulk actions, it is much more efficient to use a single SQL node instead of an aggregate + loop + update. In your example, you have an entity called "clearAllData" with an attribute "isActive" - you can create a SQL statement such as this:

UPDATE {clearAllData} SET {clearAllData}.[isActive] = FALSE

Then, just add a return structure to the SQL node (I like to use BulkActions from OutSystemsUI but it really doesn't matter since you aren't returning anything). This way you are executing 1 SQL statement, instead of (N+1) SQL statements.


Nova Bella Napoli, the syntax for SQL within OutSystems is that you wrap the entity name in curly brackets, and the attribute name in square brackets. See here for more: https://success.outsystems.com/Documentation/11/Developing_an_Application/Use_Data/Query_Data/SQL_Queries


Hope that helps!

Yeah, I agree, it's a best practice to do with SQL, but OutSystems gives us all these tools, and people that don't know how to use SQL will use more these kinds of "ways to do things". But I agree that we must use more SQL because in terms of performance and readability(in some cases) is better!

Thank you for your answer Craig St.Jean, really!!

Kind Regards,

Márcio



As always, again thank you Márcio, it worked perfectly ... 

And I will also test with SQL to have two options ...

Yeah, it's always good to know that option. In the future, in some cases, you will need to use it more often because of the best practices and the performance that I said and because of what Craig St.Jean said about being more efficient.

Glad that I helped you! Feel free, anytime! :)

Kind regards

Márcio

Craig,

Hello ... I agree with you as well as with Márcio, since Outsystems we give these possibilities, but for my case, I believe to be better SQL even. I did the following:

I created an action on the client side and called an action on the server, after validation in the client action.


See what I was returned ...

The table exists and the attribute too, however, returned me error ... could you help me please?

mvp_badge
MVP


Hey! Instead of 'TRUE', can you try setting the value to 1?

Hello my Professor Márcio. I learned from your way to do the update, but as I could, following your example, do with the SQL command, could you show me?

As always, thank you.

MARCELO SAMPAIO

mvp_badge
MVP
Solution


Hello again!

Your query is correct, you just can't use Test to actually make the update. Also, an update does not return any rows, which is why it says no rows were returned.

Regarding your error, you need to remove the input parameter to the query (GerTarDia) as it is not used in the query.

Hope that helps!

Craig, thank you again. It worked perfectly ... and Márcio,

Thank you and disregard my previous request ...

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