23
Views
11
Comments
Solved
My DataBase is changing all data instead of only one
Application Type
Traditional Web

Hey! So, I am working on a app to track my tasks and it says the Custos (cost), when i started, when I finished it, the time that I used and a bunch of other information.

But, when I create a new task and update it , it changes both dates and Custos of my 2 tasks when I only want to change the one that I updated.

You can see that "Duração da tarefa"(DataFim) should be 2 but it is 4, for example
Hope you can help me, if you want, my OML file is on the comments

mvp_badge
MVP
Rank: #114
Solution

Hi Goncalo,

I have checked your OML and I think the problem is in this UpdateTasks action. 

Here you are selecting task without any where condition and using current record of the aggregate in Data assignment so it will always calculate the DataFim and Custos with reference to the first record

Another issue is that you are passing same values in UpdateTasks SQL for all taskids (Split_String.List). So it will update all records because this list contains all Task Ids (when you drag and drop them from one bucket to other.

Rank: #25462

OML File here :)

ScrumBoard.oml

Hi Goncalo,

It seems like you are not using the filter conditions properly in Aggregates while processing the changed records. While the server action. During the UpdateTasks action, use filter conditions to fetch only the required records which needs to be modified and perform the updates to that particular record alone. Else, you would be updating all the records which are fetched by the aggregate. Hope this helps you.

Rank: #448

Hi Goncalo,

As per my analysis of the attached .OML, I did not see any issue with the cost attribute. However, for the two dates (Data and DataCriacao) you had assigned default value currdatetime() into the tasks entity. So, whenever you are trying to update the tasks both dates are getting update with same value.


Thanks & Regards,

Sachin

mvp_badge
MVP
Rank: #114
Solution

Hi Goncalo,

I have checked your OML and I think the problem is in this UpdateTasks action. 

Here you are selecting task without any where condition and using current record of the aggregate in Data assignment so it will always calculate the DataFim and Custos with reference to the first record

Another issue is that you are passing same values in UpdateTasks SQL for all taskids (Split_String.List). So it will update all records because this list contains all Task Ids (when you drag and drop them from one bucket to other.

mvp_badge
MVP
Rank: #2

Hi Gonçalo,

Unfortunately, there seems to be quite a bit wrong with your code, and there are some questionable decisions. For one, if you are a starting OutSystems developer, I would strongly suggest you create a Reactive App, not a Traditional Web App. Traditional Web Apps are bwecoming legacy, and all new development will be on Reactive. Also, Reactive is more versatile and the user interface more responsive. Secondly, you added JQuery. Unless you are an experienced OS developer, and really know what you're doing, adding JavaScript scripts like this is a disaster waiting to happen. You really do not need it in 99% of the cases - my experience is that people coming from a JavaScript background love to include all kinds of scripts that are really not needed when developing with OutSystems.

That said, let's look at your code. In the ScrumBoard Web Block, the List Records is bound to GetTaskStates.List. However, in the TaskState Expression, you use GetTaskStates.List.Current, instead of the lrTaskStates.List.Current, something you correctly do in the inpSortOrder Input. You make the same mistake in the tasks Expression (GetTaskStates.List.Current is input to the CreateTaskList Function).

Then, in OnChangeOrderTasks, you query all Tasks, sorting by description, but loop over lrTaskStates.List, the contents of the List Records. But in the call to UpdateTasks, you use lrTaskStates.List.Current for TaskStateId and TaskIds (which seems correct), but GetTasks.List.Current for Data, DataFim and Custos, which will always be the value of the very first Task, alphabetically (since without using a For Each, the Current will be the first record). That seems wrong!

Inside UpdateTasks, there's another GetTasks, and you again use the Current, again alphabetically the first record, to actually overwrite the wrong values of Data, DataFim and Custos. Why are these input parameters at all if you're going to overwrite them? Then you loop over the result of the String_Split, which is apparently a list of Task Ids (I can't even make out how they're filled), and you update using a SQL query. That is weird in itself - why not use a single UpdateTask Entity Action? But it's also weird because you use four UPDATE statements to update the same record - and judging the first statement, you already understand you can update more than one attribute with a single UPDATE. That said, what goes as input to the SQL is the values associated with the very first Task, alphabetically, so all tasks in the list will get the same values.

Concluding, this code really is a big mess. I've only looked at part of it, but there's so much wrong with it, probably everything is this bad. I would advice you to take all the OutSystems free courses if you haven't already, to get a better feel of how to develop using OutSystems, because as it stands, this is really not how to do it.