Fetch values when a document is created from another one (from Quotation to Sales Order)

Hi there,

I have a custom script in sales order, and I try to fetch some data from the customer.


If I select the customer in Sales Order, it works.

The problem appears when I create a Quotation, and from the Quotation document I make a Sales Order (with the button). ERPNext autofetches the Customer from the Quotation to the Sales Order. So, the problem is that after that I can not fetch my values that depends in the Customer doctype.

We have tried things like:

  • Use a setTimeout.
  • Use a set value (to copy to another field and then copy it again).
  • Use a frappe call.

Any idea about how to fetch data in a custom script from a server side fetched value?

Kind Regards,


Hi @rtimagine, did you used frappe.db.get_value?

Hi there Thiago_Henry,

We have tried with this:

setTimeout(function() {
“method”: “frappe.client.get_value”,
args: {
doctype: “Customer”,
fieldname: “customer_name”,
filters: {
name: [“=”, frm.doc.customer]
callback: function(data) {
cur_frm.set_value(“customer”, data.message.customer_name);
}, 1000);

But it didn’t work.

Any idea? Thanks!

yes try this

frappe.db.get_value(“Doctype”, { name: cur_frm.doc.ZXXXXX },
“field”, function(data){
cur_frm.set_value(“field”, data.field); });

I guess that you can put it inside TimeOut

Check this: https://frappe.github.io/erpnext/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/custom-script-fetch-values-from-master

Hi there,

rmehta, add_fetch is not working cause it is first fetched in python by ERPNext. It’s not very clear the way to do this in the documentation.

Thanks Thiago, it worked with this:

frappe.ui.form.on(“Sales Order”, “onload”, function(frm) {
frappe.db.get_value(“Customer”, { name: cur_frm.doc.customer },
“test”, function(data){
cur_frm.set_value(“test”, data.test); });

So, it’s solved!

Kind Regards



Can you please tell me if I want to fetch the value of GSTIN from customer doctype to the quotation doctype, then How will code be seen after edited?

frappe.ui.form.on(“Quotation”, “onload”, function(frm) {
frappe.db.get_value(“Customer”, { name: cur_frm.doc.customer },
“gstin”, function(data){
cur_frm.set_value(“gstin”, data.gstin); });

Please check it and correct me.

do you find answer to your question?