How to update values of certain fields in a database?

How to update values of certain fields in a database?

  

I might not understand how the table updating works. My app logic requires me to first create a new row, with one value empty (column 'Left' below), and then update this value later. It seems to me though that if I use the Update function, it just rewrites the whole row. Also, right now I can't even update. I thought I could find the biggest ID in an aggregate, and update the database based on that ID. However, when I try to do that, the database comes back with an error, stating it cannot update the row with key 0 (right now, only IDs bigger than 10 exist in the table), so it seems I can't even find the proper row I want to update. 

So in below example, I would like to update the row with ID 18 with a new date in the column 'Left'.

To show you, this is the aggregate:

And I'm trying to update like this:

Where am I wrong here?

The Current only has content when you are looping through the table. In a ForEach or a Table for instance. Asking for Current out of the list, you get a null row. And when you update a row with null id (value 0) it creates a new one.

You need a query that finds the max id (Order by Id desc, Max Records=1) and then work that row.

_____

Of course the best solution would be for the action to receive an id as parameter, and then you'd just have to search for the id with action GetUser.

Nuno Reis wrote:

The Current only has content when you are looping through the table. In a ForEach or a Table for instance. Asking for Current out of the list, you get a null row. And when you update a row with null id (value 0) it creates a new one.

You need a query that finds the max id (Order by Id desc, Max Records=1) and then work that row.

_____

Of course the best solution would be for the action to receive an id as parameter, and then you'd just have to search for the id with action GetUser.

Do I do this in an aggregate still? Where can I find the option to sex Max Records?

Nuno Reis wrote:

The Current only has content when you are looping through the table. In a ForEach or a Table for instance. Asking for Current out of the list, you get a null row. And when you update a row with null id (value 0) it creates a new one.

You need a query that finds the max id (Order by Id desc, Max Records=1) and then work that row.

_____

Of course the best solution would be for the action to receive an id as parameter, and then you'd just have to search for the id with action GetUser.

Also, if I aggregate to Order by Id desc, Max Records=1, how do I get the value to the action from the aggregate?

 To set max records there is a specific box.

You couldn't get the rows from preparation because of the change of scope. Now you can get the right one easily. It is the only one.




Nuno Reis wrote:

 To set max records there is a specific box.

You couldn't get the rows from preparation because of the change of scope. Now you can get the right one easily. It is the only one.




Thank you! My question refers to how to assign the value from the aggregate to a value? So what do I put here:

to access the Id in the one-row aggregate?


Dear Csanád Póda,


The part of your client action to store away date should look a bit like this.

First of all you have your aggregate with 1 record, then in your assign you take the record in that aggregate that you want update so in ur case it will be something like "aggregate.list.current.collumnname"= currDateTime(). After that as source in your updateaction you just take the aggregate list -> "aggregate.list.current".

Excuse me for my english, but I hope this helps you

Csanád Póda wrote:

Thank you! My question refers to how to assign the value from the aggregate to a value? So what do I put here:

to access the Id in the one-row aggregate?


I misinterpreted. You're trying to update the logger, not the users. Ok, that is less terrible.

To get the higher id from Logger, apply the MaxRecords and order by desc to a GetLogger aggregate. 

The value you want is in GetLogger.List.Current.Id (it is the default name, is your field really called IdMax?).



Nick Vandebriel wrote:

Dear Csanád Póda,


The part of your client action to store away date should look a bit like this.

First of all you have your aggregate with 1 record, then in your assign you take the record in that aggregate that you want update so in ur case it will be something like "aggregate.list.current.collumnname"= currDateTime(). After that as source in your updateaction you just take the aggregate list -> "aggregate.list.current".

Excuse me for my english, but I hope this helps you

The issue stays the same, as I can't seem to assign the aggregate to a value... I'm trying like this:

And also like this:

But the list is always null... My program currently looks like this:


No idea what I'm doing wrong.

It looks you are doing the right thing, but the yellow alert means it may not be of the right type. Shouldn't IdToUpdate be Logger Identifier?

Can you debug and check the value in IdToUpdate?

Nuno Reis wrote:

It looks you are doing the right thing, but the yellow alert means it may not be of the right type. Shouldn't IdToUpdate be Logger Identifier?

Can you debug and check the value in IdToUpdate?

I changed the type, but it didn't help... I can't debug, because I'm using the online devenv, and the debugger is only available in the desktop version (which is not available for a Mac...)

To be sure if the problem is getting the id or saving, hard-code the id you want: 

If you want to write into log 18, set Id as IntegerToIdentifier(18)


Hi!  I'm not sure I'm following the issue entirely but Nuno's last logic will work to map your Id: IntegertoIdentifier(GetLocalLoggers.List.Current) or IntegertoIdentifier(IdtoUpdate).  Changing the type won't work on an aggregate becuase you're returning an integer, not an Id. If you're still receiving the "Cannot update with key 0" error then your query is not returning what you think it is so I would check the inputs and/or filters.  

One more thing - as a matter of preference I usually create a single local variable of type record for the record I'm wanting to update/create then assign the attributes from the outputs of the actions immediately before I perform the logic...this is an alternative to using the Platform's mapping ability and very helpful when creating validation or additional logic prior to CRUD actions.