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

I am trying to get and put last four fields value to my new created record from the latest created in my custom doctype, No luck working the client side scripting in ERPNEXT 13.

I need this to calculate the difference between today and yesterday value, ie:

resultfield = fieldnew1 - field1

Here My Client Script:

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,"fieldnew3": result.field3, "fieldnew4": result.field4 })
            frm.save();
        })
    }
});

What I want is to automatically fill the field value.

This is the Sample Result



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source