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 })
            frm.save();
        }
    }
});

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 (http://192.168.0.100/assets/js/form.min.js?ver=1652140582.0:17294:19)
at FrappeForm.setup (http://192.168.0.100/assets/js/form.min.js?ver=1652140582.0:19925:24)
at FrappeForm.refresh (http://192.168.0.100/assets/js/form.min.js?ver=1652140582.0:20163:11)
at FormFactory.render (http://192.168.0.100/assets/js/form.min.js?ver=1652140582.0:14520:46)
at http://192.168.0.100/assets/js/form.min.js?ver=1652140582.0:14504:12
at Object.callback (http://192.168.0.100/assets/js/desk.min.js?ver=1652140582.0:9858:20)
at Object.callback [as success_callback] (http://192.168.0.100/assets/js/desk.min.js?ver=1652140582.0:3765:17)
at 200 (http://192.168.0.100/assets/js/desk.min.js?ver=1652140582.0:3809:35)
at Object. (http://192.168.0.100/assets/js/desk.min.js?ver=1652140582.0:3953:7)
at i (http://192.168.0.100/assets/frappe/js/lib/jquery/jquery.min.js:2:27151)

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