Expand section break programaticaly

I have added a section break to an existing form.
I am able to add a code snippet such that when a link is clicked my section break expands

frm.fields_dict[‘project_expenses’].collapse(false);
Which works fine.

I would like to do this automatically in
frappe.ui.form.on(‘Sales Invoice’, {
refresh: function (frm) {
if(somecondition){
frm.fields_dict[‘project_expenses’].collapse(false);
console.log(“expanding”);
}
},

but it never does anything. I see the console message. The section remains collapsed
I have also tried onload and onload_post_render

Does anybody know when the docuement is actually ready.