Get old data from same table for summarizing

Hi community
I have a scenario where i need to get old data from a table via sql query and add to it the current values to have a sum which will be stored in the same data entry automatically.

Regards

Is it ERPNext related question or SQL? Sorry, your query is not very clear, can you explain little bit more.

Yes it is erpnext related i already try it in custom script frappe.db.sql but i get nothing if you can show me an exemple how to get data from database after a field selection
Thank you @KanchanChauhan
Regards

please share your custom script

please check the frappe.db.get_value method https://github.com/frappe/frappe/blob/develop/frappe/public/js/frappe/form/footer/timeline.js#L194

thank you @makarand_b
this is my code

` frappe.ui.form.on(“Gaz Consumption”, {
validate: function(frm) {
frm.trigger(“calculate_area”)
},

daily_production: function(frm) {
	frm.trigger("calculate_area")
},


calculate_area: function(frm) {
	if (frm.doc.daily_production){
		d = frappe.datetime.add_days("2016-05-03", -1);
		fetch = frappe.db.sql("Select cumul from `tabGaz Consumption` where date = (%s);",frappe.datetime.add_days(self.date),-1);
		area = flt(frm.doc.daily_production + fetch);
		frm.set_value('cumul', area);
	}
}

})`

frappe.db.sql is python method and can not be access on the client script, use the frappe.db.get_value method instead.

frappe.db.get_value("DocType Name", filter, fields, callback)

e.g. frappe.db.get_value("Gaz Consumption", {date: frappe.datetime.add_days(self.date),-1)}, "cumul", function(r) {
	frm.set_value("cumul", r.cumul)
})

e.g.

1 Like

shows me blank form
this is the final code

` frappe.ui.form.on(“Gaz Consumption”, {
validate: function(frm) {
frm.trigger(“calculate_area”)
},

daily_production: function(frm) {
	frm.trigger("calculate_area")
},

calculate_area: function(frm) {
	if (frm.doc.daily_production){
		frappe.db.get_value("Gaz Consumption", {date: frappe.datetime.add_days(self.date),-1)}, "cumul", function(r) {
frm.set_value("cumul", r.cumul);

})
}
}
})`

hi @makarand_b
after some modifications i get the form and this error makes me crazy

any idea

after some diging i do not get cumul field in the debugger list

@SOLOSOFT,

check the frappe.db.get_value result try to print the value of r in console e.g. console.log(r) and check if you are getting the cumul field.

Thanks,
makarand