Try ERPNext Buy Support Partners Foundation

Fetching State field from Address doctype onto sales order form

Hi there,

I am using Ver 4 of erpnext (I know I should upgrade and I’ll soon)

Need to pull a State field under Address onto Sales Order form, both screenshots are provided below,

Address form State field-

Newly created State field on SO form where I want to pull data of the original State field on Address form-

I tried using Type as Link and then putting doctype as Address but it’s not auto populating in SO form. What am I doing wrong?

Any help would be appreciated!

bump bump…

Hi, try to change type to Data, add customer_address.state to Fetch From field and keep Address in Options field. But not sure if it works with v4, I’m using v12.

Thanks Martin, appreciate it! However, I can’t see any field called ‘Fetch From’. May be it’s not an option on Ver 4. Any other solution?

Bump bump…

Set type as data and remove Address from options. Scroll down you will find a field ‘Fetch From’, set its value to ’ customer_address.state’.

Something like this:

If there is no fetch from field in V4, you can call AJAX to set the value of State, just set the field_type of State to Data and for reference see follow,

You have to reselect the value of Customer Address to trigger this AJAX.

Just put this code in the Custom Script of Sales Order.

frappe.ui.form.on(‘Sales Order’, {
customer_address(frm) {
if(frm.doc.customer_address){
frappe.call({
method:“frappe.client.get_value”,
args: {
doctype:“Address”,
filters: {
name:frm.doc.customer_address
},
fieldname:[“state”]
},
callback: function® {
frm.set_value(‘state’, r.message[‘state’]);
}
})
}
}
})

1 Like