How to get max(DeliveryNoteNumber) using custom script? or SQL Query

I have thirteen series of Delivery Note and want to know that the last number of that series.

Please help.


Using MySQL,you can find out Delivery note number

select max(name) from `tabDelivery Note`;

select last(name) from `tabDelivery Note`;

Thanks a lot Sharssha, Please tell me how to call in custom script?

D## ear Shraddha,

I wrote the following script to get max(delivery note number) for a series because I have 10 series and users want to know the last number entered for the DN series.

Please help.

cur_frm.cscript.consignee = function(doc, cdt, cdn) {

var d = locals[cdt][cdn];

result_value = “”;


result_value=cur_frm.set_query(“Delivery Note”, function (doc, cdt, cdn) {

return {

“query”: “select max(name) form tabDelivery Note where name like %s”,

“txt”: “KMT-”




frappe.model.set_value(cdt, cdn, “gr_number”, result_value);