Fetch the latest entry created in a doctype order by the latest date field

Is there any link or documentations to do the report something like what need to be done, I don’t have any idea scripting in report, I can write client script for calculation if the required fields value is there. that’s why I would refer to do it in the form side.

Thank you for this @peterg will take a look at this link after.
in the meantime I will test this first

frappe.ui.form.on("Monitoring", {
    "refresh": function(frm) {
        frappe.db.get_list("Monitoring", {fields: ['*'], order_by: "creation desc", limit: 1}).then((result) => {
            frm.set_value({"fieldnew1": result.field1, "fieldnew2": result.field2 })

Agree with @peterg . Duplicate data in each new record may result unconsistent … The report just should show data of each record and add values of previous record. Probably that’s the best way.

Anyway, “refresh” event occurs every time you load a form. Note that this behavior will overwrite your previous data. Try “setup” event instead, this only occurs just on record creation.

Create doctyle Monitoring and copy and paste the script

@peterg I got Error message:

Error in Client Script
SyntaxError: missing ) after argument list
at init.setup (
at FrappeForm.setup (
at FrappeForm.refresh (
at FormFactory.render (
at Object.callback (
at Object.callback [as success_callback] (
at 200 (
at Object. (
at i (

Which I expect to auto fill the 2 fields: fieldnew1 and fieldnew2

Sorry James, I can’t help you any further. There’s a syntax error in the code I posted, as I said there probably would be. It’s missing a ) somewhere. If you’re not able to track down the problem and fix it yourself, I’d encourage you to back up a step and spend some time learning javascript. This forum is not really well suited to the kind of support you are needing.

Ok thanks really appreciate the help and your time