Refresh without forcing

Using this script to grab batch status from the Quality Inspection doctype. Works great BUT I have to use alt-refresh on the browser to get the updated status when it changes. Any way to have this automatically refresh??

frappe.ui.form.on("Batch", {
onload:frappe.call({
    method:"frappe.client.get_value",
    async:true,
    args:{
        doctype:'Quality Inspection',
        filters:{
            batch_no:cur_frm.doc.batch_id
        },
        fieldname:['status']
    },callback:function(r){
        console.log(r.message);
        if(r.message !== undefined){
            cur_frm.set_value('status', r.message.status);
            cur_frm.refresh_fields('status');
            frm.refresh();
        }
    }
  })
});

THIS is what finally worked, subtle difference:

frappe.ui.form.on("Batch", { 
   refresh(frm){
		frappe.call({
    		method:"frappe.client.get_value",
    		async:false,
    		args:{
        		doctype:'Quality Inspection',
        		filters:{
            		batch_no:frm.doc.batch_id
        		},
        		fieldname:['status']
    		},callback:function(r){
        		console.log(r.message);
        		if(r.message !== undefined){
            		alert(r.message.status);
            		frm.set_value('status', r.message.status);
            		frm.refresh_fields('status');
        		}
        		//location.reload(); //Makes the doc load endlessly
    		}
		});
   }
});

The alert is in there to verify the script is running and is unnecessary.

1 Like