Need help creating a read only date field

Hi,

I am trying to great a date field from the “from_time” field from the sales invoice timesheet detail table. I am having an issue creating a date field based off “from_time” datetime field.

Steps taken:

  1. Customized sales Invoice Timesheet to add a new Date field
  2. Added a default value to the date field: from_time.format("YYYY-MM-DD")

Getting an error when saving the changes:

pymysql.err.OperationalError: (1067, "Invalid default value for 'custom_start_date'")

I really just need this date field to be read only and will be using in reporting and printing.

Any help is appreciated.

Thank you.

Hi @varunpan

You can only set default value for Date field as Today.

How can I automatically update my custom field to have the date value of the from_time field from the sales invoice timesheet details?

if it is Datetime field then you can set default as Now.

from_time is a datetime field on sales invoice timesheet child table
I created a new custom_start_date date field on sales invoice timesheet child table

I want to get the Date portion from the datetime field from_time and add it to the custom_start_date field.
For example:
if from_time is 2025-05-07 20:06:52 then I want custom_start_date field to be auto populated with 2025-05-07.

I understand that I cannot had a formula in default value, therefore, I wrote a client script but it does not update the field and I’m not sure why:

frappe.ui.form.on('Sales Invoice', {
	refresh(frm) {
		// your code here
		
	}
})

frappe.ui.form.on('Sales Invoice Timesheet', {
	validate: function(frm) {
		if (!frm.doc.from_time && !(frm.doc.custom_start_date = moment(frm.doc.from_time).format('YYYY-MM-DD'))) {
		    frm.doc.custom_start_date = moment(frm.doc.from_time).format('YYYY-MM-DD');
		}
	}
})

I also tried to use refresh instead of validate but did not work.