Insert Data during Hook 'Before Insert'

Dear All,

I hope that you are doing excellent.

I have an issue and request some help.

I have a collection (Directors) with a field Date and I would like to insert the date 01.01.1900 as default date.

So I created a hook as follow:

//INSERT DEFAULT DATA
export function Directors_beforeInsert(item, context) {
    item.active = "No"
    item.initialDate = ("1/1/1900")
    //
    return item;
}

The date is inserted well but on the collection I have this display

How can I modify my code ‘item.initialDate = (“1/1/1900”)’ to avoid this warning on the date field.

For your information: new Date(“1/1/1900”) does not work.

Thank you for your help.

Best regards,
Domivax

Your problem is, that you do not differ between different types of DATABASE-FIELDS.

A DB-Field can be a …

  1. boolean-field
  2. string-field
  3. object-field
  4. array-field
  5. date-field
  6. and so on…

about new Date…

console . log ( new Date ( “01/11/1999” ));
console . log ( new Date ( “12/28/2022” ). toLocaleString () );
//-----------------------------------------------------

let day = "...";
let month = "...";
let year = "...":
let myDate = new Date (new Date(`${month}/${day}/${year}));
console.log(myDate);
  1. First setup your dbField to your wished Field-Type (date or string) ???
  2. Then also put the right converted type into your DB-Field.