60
Views
9
Comments
Solved
Update just one attribute of entity

Hi,
I'm developing an app to track when an employee starts and finishes work.
I want to create a button that, when clicked, saves the exit time (the time the employee finishes work), but does not update the other fields in the record.
What's the best way to do this? 

2020-05-07 18-53-00
Rui Barradas
 
MVP
Solution

@Guilherme Gomes in my first comment you have an example of what Nuno just described. That’s an example of a CRUD action that you can adapt for your use case.


By fetching the record you want to update, all the fields will already be populated with their current values. Then you need to assign the field you want to the value you want. And execute the update in the end.

2020-05-07 18-53-00
Rui Barradas
 
MVP

Hello Guilherme,

Hope you're doing well.

Each entity has entity actions, these will allow you to manipulate the records inside that entity:

But you need a key to identify the record you want to update (usually it's the Id).

After retrieving the record you want, just use an Assign on the field you want and use the Update<Entity> Action.


Kind regards,

Rui Barradas

2016-04-22 00-29-45
Nuno Reis
 
MVP

Although in OutSystems Update Actions updates the entire record, you can do that in two ways.

  1. Specifically in Advanced SQL.
  2. Or the smart way (and probably enough for compliance): set the entity to update only changed attributes.

Go to Indexes and More on the properties:

And there choose to only update "Changed Attributes" instead of "All Attributes".

2023-05-31 07-26-04
Hiren Rathod

Hey Nino,

can you elaborate more how to do that after selecting the update behavior

regards,
Hiren

UserImage.jpg
Sowmya K

Hi Guilherme Gomes,
In the entity update action, you can pass only the specific field (e.g., DiscardDateTime, DicardNote) that needs to be updated. 


UserImage.jpg
Guilherme Gomes

This is happening... It's setting the others to null



2016-04-22 00-29-45
Nuno Reis
 
MVP

You still need to send all attributes. But the internal SQL will only update the ones that are actually different.

The only way of not writing all the parameters is if you create a CRUD that receives the Id and the new parameter, fetches the record, assigns the value and does the update.

2020-05-07 18-53-00
Rui Barradas
 
MVP
Solution

@Guilherme Gomes in my first comment you have an example of what Nuno just described. That’s an example of a CRUD action that you can adapt for your use case.


By fetching the record you want to update, all the fields will already be populated with their current values. Then you need to assign the field you want to the value you want. And execute the update in the end.

UserImage.jpg
Guilherme Gomes

Thank you all guys!

2021-09-06 15-09-53
Dorine Boudry
 
MVP

I know this might not be the preferred / low code way to do it, but for some specific updates (like moving forward the state of something) I like to write dedicated server actions that use sql to do this one specific task, no need to first use an aggregate for retrieval, only a single sql node.

If I want my code to be even more verbose / explicit, I make actions to move forward to a specific state, that contains all checks to make sure this particular move is allowed.  I find that in complex lifecycles of an entity, it is very informative for future developers to be able to

  • see exactly in which contexts a specific state can be set (with a find usage of that action)
  • easily find all the business rules involved with setting that state
  • easily identify what down-stream effects could result from setting that particular state

Dorine

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