frappe.ui.form.on('*', {
refresh(frm) {
// Hide the Duplicate button for specified user roles
if (frappe.user_roles.includes("Administrator") || frappe.user_roles.includes("Desk User")) {
frm.page.menu.find('[data-label="' + __("Duplicate") + '"]').parent().parent().remove();
}
}
});
this does not work for all doctypes?
ejaaz
2
I don’t know about “*” but if you are adding code in doctype_js.js
, it will work only for that doctype.
i know that i want to delete the duplicate button for all system user
in all doctype
ejaaz
4
Try creating a JS file and include it in the app_include_js
hook, and modify your code based on that. Your final code will look something like this.
if (frappe.user_roles.includes("Administrator") || frappe.user_roles.includes("Desk User")) {
cur_frm.page.menu.find('[data-label="' + __("Duplicate") + '"]').parent().parent().remove();
}
https://frappeframework.com/docs/user/en/python-api/hooks#desk
1 Like
ejaaz
6
It is working or not?
Try this; it worked for me.
$(document).ready(function(){
setTimeout(() =>{
if (frappe.user_roles.includes("Administrator") || frappe.user_roles.includes("Desk User")) {
cur_frm.page.menu.find('[data-label="' + __("Duplicate") + '"]').parent().parent().remove();
}
}, 1000);
});
not working
i tried this two some page need more than this time to be ready
i try this now and check it but not work in all senarios
$(window).on('hashchange', page_changed);
$(window).on('load', page_changed);
function page_changed(event) {
// Waiting for the page to load completely
frappe.after_ajax(function () {
var route = frappe.get_route();
if (route[0] === "Form") {
var doctype = route[1];
// Check if the event handler is already set
if (!frappe.ui.form.on[doctype]) {
frappe.ui.form.on(doctype, {
refresh: function (frm) {
console.log("doctype = " + frm.doctype);
if (frappe.user_roles.includes("Administrator") || frappe.user_roles.includes("Desk User")) {
cur_frm.page.menu.find('[data-label="' + __("Duplicate") + '"]').parent().parent().remove();
}
}
});
}
}
});
}
this worked
thx @ejaaz @Mohammed_Redha
on which file did you save this? is there any hook setting to do before this?