Need to fetch branch in accounting dimensions

Hi,

I need to fetch branch in accounting dimensions both in sales order and sales invoice. I used below code,

frappe.ui.form.on(‘Sales Invoice’, {
branch: function(frm,doc) {
var branchname = frappe.model.get_value(“Sales Order”, doc.name,“branch”);
frm.set_value(“branch”,branchname);
}
}
});

its fetching when i create sales invoice from sales order but when i am directly creating sales invoice the branch is vanishing. I tried cur_frm.add_fetch(“Sales Order”,“branch”,“branch”); but its not fetching. Kindly help.

Thanks in advance!