Is there a way to run a script on another doctype?

Hi everyone!

I’ll try to define my use case as clear as I can.
I have 2 Doctypes:

  • GMC11
  • GMC12
    Each doctype has a child table. Let’s call them:
  • GMC11B
  • GMC12B

GMC11B gets filled with values inside GMC12B using refresh trigger as follows:

frappe.ui.form.on("GMC11", {
	refresh: function(frm) { 
		cur_frm.clear_table("b_11_0322_table"); 
        	frappe.call({
        		method: "frappe.client.get_list",
        		args: {
        			doctype: "GMC12B",
				parent: "GMC12", 
                		filters: {"a_12b_0322_tarea": frm.doc.name},
			        limit_page_length: 200,
			        fields:["parent", "a_12b_0322_inicio", "a_12b_0322_fin"],
        		},
        		callback: function(r) {
        			$.each(r.message, function(index, value) { 
        		        	var new_row = frappe.model.add_child(frm.doc, "GMC11B", "b_11_0322_table");		
					new_row.registro = value["parent"];
					new_row.b_11b_0322_inicio = value["a_12b_0322_inicio"];
					new_row.b_11b_0322_fin = value["a_12b_0322_fin"];
  					
        			}); 
				refresh_field("b_11_0322_table");
        			
        		}
		})
	},
});

This works fine but in order to run the script I need to enter the form, the script runs and the I have to save it.

What I need to do is:

  • Create a script for GMC12 that triggers with “after_save” and runs the script for GMC11 and automatically saves the changes

Sequence:
Changes are made in GMC12B (new rows, new data, etc) > GMC12 is saved > Script for GMC12 runs > It makes GMC11 script run > GMC11B gets updated > GMC11 is saved automatically.

Basically that the first script triggers the second one. The action will be similar to this but instead of “set_value” I need to run the GMC11 script descripted above:

frappe.ui.form.on('GMC12', {
    after_save(frm) {
	frappe.call({
            "method": "frappe.client.set_value",
            "args": {
                "doctype": "GMC11",
                "name": frm.doc.vinculo,
                "fieldname": "prueba_01",
                "value": frm.doc.dato1
            }
        });
    } 
});

Any help is welcomed. Thanks!

Any help?