ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

[Tutorial] Push changes to another document


#1

An example script showing how to push changes from one doc to another.


How to create entry in other forms using custom script
Sum of Items (z = x+y)
#2

Hey thanks @cpurbaugh. Script works perfectly!

Had one doubt, How to trigger the function on document save event, instead of calling it on update button?

Update: Got Through, called below function on “validate” event instead of refresh.

    function() {
        frappe.call({
            "method": "frappe.client.set_value",
            "args": {
                //replace "Target DocType" with the actual target doctype
                "doctype": "Target DocType",
                //replace target_doctype_link with a link to the document to be changed
                "name": frm.doc.target_doctype_link,
                "fieldname": {
                    //You can update as many fields as you want.  
                    "target_field_1": frm.doc.source_field_1,
                    "target_field_2": frm.doc.source_field_2,
                    "target_field_3": frm.doc.source_field_3,
                    "target_field_4": frm.doc.source_field_4,
                    "target_field_5": frm.doc.source_field_5  //Make sure that you do not put a comma over the last value
                },
            }
        });
});

#3

Glad it helped!


#4

Heyy @cpurbaugh

I’m trying that, I completed the code you gave us, but I missing the target doctype link, I’m new on this, and a really want to know how should the link be?


#5

it should be a link field in your source. You can use customize form to find link fields or create your own.


#6

@cpurbaugh very helpful code indeed, i was using something like that but i needed it to upon submit go create and autofill a doc then save it without waiting for me to manually save it, maybe it can be done in the background.
p.s. i can only use custom script, cant access any files or folders other than the simple client side editing.

thank you in advance

Edit:
and i also wanted to ask can i use this method to add rows and fill them in a child table?


Best regards


#7

Dear @cpurbaugh

I’m tried to using the script to update field value in child table in quotation item from sales order item put not working

frappe.ui.form.on("Sales Order Item", {
	refresh: function(frm) {
		frm.add_custom_button(__("Update"),
			function() {
				frappe.call({
					"method": "frappe.client.set_value",
					"args": {
						"Sales Order Item": "Quotation Item",
						"name": frm.doc.prevdoc_docname,
						"stage": {  
							"stage": frm.doc.stage
						},
					}
				});
		});
}
});

#8

[Newbie alert!] What is target_doctype_link in the above code? Target DocType name?


#9

in the source document, there would be a link to the target document. target_doctype_link would be that field’s name.