Hide Create Purchase Order button based on

Hello All,

I have a scenario where I need to prevent the creation of multiple Purchase Orders from a Supplier Quotation. Currently, there is no built-in option to close a Supplier Quotation. Since I already have a workflow on the Supplier Quotation Doctype, I added a Closed status. The intention is that when the form reaches this status, the Create Purchase Order button should disappear. However, the client script does not work when I include this condition.

frappe.ui.form.on(‘Supplier Quotation’, {
refresh(frm) {
if (frm.doc.workflow_state === “Closed”) {
setTimeout(() => {
frm.remove_custom_button(‘Purchase Order’, ‘Create’);
}, 10);
}
}
});

Kindly advise on this issue.

Thanks

We have been able to modify the script however now the connections are also removed.
Is this normal behaviour and how to prevent this?

frappe.ui.form.on(‘Supplier Quotation’, {
refresh(frm) {
if (frm.doc.workflow_state === “Closed”) {
frm.page.remove_menu_item(__(‘Purchase Order’), __(‘Create’));
}
}
});