Fetch document from link field

frappe.ui.form.on(“doctypename”, {
wb_no: function(frm) {
var selected_kanta_no=frm.doc.wb_no;
doc = frappe.get_doc(‘Weigh Bridge’, ‘selected_kanta_no’)
frappe.msgprint(“document is”, doc);


i am trying to fetch selected doctype (in different doctype) which is obtained from link field but i m getting doc as null. i m not able to fetch that document. can anyone help me on fetching doctype by using this way?, any help will be more helpful.

use the frappe.call to fetch the another document instead of frappe.get_doc.


	method: "frappe.client.get",
	args: {
		doctype: "your_doctype",
		name: "your_docname",
		filters: "filters if any"
	callback(r) {
		if(r.message) {
			doc = r.message

Thanks, Makarand

@makarand_b but name of particular doctype is coming from link field in other words it is dynamic.

you can put your document type and name dynamically in doctype and name argument

@makarand_b after updating one field in that document that i just fetched and if i try to save it using doc.save() it is showing error in console as doc.save() is not valid function.

1 Like

Hi where did you call doc.save()? It should be called in python files

@johnskywalker i m calling it in js file. can u please give example on how to fetch document in python code and save it in database.it will be more helpful.

I think doc.save() should be in python not in .js

1 Like

@johnskywalker thank you so much you are right.

1 Like

you are welcome :slight_smile: