Initialize fields when adding or copying record

Hi,

I have a record in a table with a field, let’s say: ‘interventionDate’.

Example. Today = 13/3/2020.
Existing record 1: interventionDate = 1/1/2019

Now, there are 3 possibilities:

  1. Edit record 1 should keep date of 1/1/2019 (works fine).
  2. Adding new record (normal add, no in-line or grid): interventionDate = today(13/3/2020) (currently achieved by field setup - add page -default value = CurrentDateTime()
  3. Copying record 1: interventionDate = today(13/3/2020) (similar as adding new record). Other fields keep original values. How to achieve this?

You may use Row_Inserting server event (see the topic Server Events and Client Scripts) to set the new value as old value, e.g.

if ($this->isInsert()) $rsnew[“interventionDate”] = $rsold[“interventionDate”]; // v2020

Hi Arbei,

Sorry for the late reply… and thank you!
I made it work the way you suggested but the field is only updated after you click “save” not taking care if the date is changed by the user (which should be possible).
Is there a way to initialise the date when the copied record is displayed, so before the record is inserted?
In that way, the user sees the new date and can correct if necessary.

You can achieve that by simply use “Row_Rendered” server event. Just assign the “EditValue” property of your “interventionDate” field by the current date, for example:

if (CurrentPageID() == “add”) { // only for the Add page
$this->interventionDate->EditValue = CurrentDate(); // just assign EditValue with current date
}

Perfect! … as usual :wink:

Thanks!