How to set the field value and based on user's role conditions on print format?

Is there anyone who can help me?

How to set the field value and based on user’s role conditions on print format?

Thanks and regards
Shubham

@Shubham_Prabhat1 , can you explain more with use case?

Example
for Asset Movement doctype case,

if doc.purpose is “Issue” then only employee role should be able to print,
and if doc.purpose is “Receipt” then only “Asset Manager” should be able to print

and
if doc.purpose is “Transfer” then “IT Engineer” should be able to print"

and

doc.purpose field has value then “Manager” should be able to print

try this client script

frappe.ui.form.on('Asset Movement', {
    refresh: function(frm) {
        // Hide the default print button
        frm.page.clear_menu();
        
        // Check conditions for showing the print button
        if (frm.doc.purpose === "Issue" && hasRole("Employee")) {
            showPrintButton(frm);
        } else if (frm.doc.purpose === "Receipt" && hasRole("Asset Manager")) {
            showPrintButton(frm);
        } else if (frm.doc.purpose === "Transfer" && hasRole("IT Engineer")) {
            showPrintButton(frm);
        } else if (frm.doc.purpose && hasRole("Manager")) {
            showPrintButton(frm);
        }
    }
});

// Function to check if the current user has a specific role
function hasRole(role) {
    return frappe.user_roles.includes(role);
}

// Function to show the print button
function showPrintButton(frm) {
    frm.page.add_menu_item(__('Print'), function() {
        frm.script_manager.trigger('before_print');
        frm.print_doc();
    });
}

Thanks for reply,
Let me try

Did not work

This script is actually affecting ( … ) dropdown list menu, not even hiding all the menus except print

using this code

frappe.ui.form.on(‘Asset Movement’, {
refresh: function (frm) {
// Hide the default print button
frm.page.clear_menu();

    // Check conditions for showing the print button
    if (frm.doc.purpose === "Issue" && hasRole("Employee")) {
        showPrintButton(frm);
    } else if (frm.doc.purpose === "Receipt" && hasRole("ERP_Employees")) {
        showPrintButton(frm);
    } else if (frm.doc.purpose === "Transfer" && hasRole("Delivery User")) {
        showPrintButton(frm);
    } else if (frm.doc.purpose && hasRole("Engineer IT")) {
        showPrintButton(frm);
    }
}

});

// Function to check if the current user has a specific role
function hasRole(role) {
return frappe.user_roles.includes(role);
}

// Function to show the print button
function showPrintButton(frm) {
frm.page.add_menu_item(__(‘Print’), function () {
frm.script_manager.trigger(‘before_print’);
frm.print_doc();
});
}

@mohitchechani

And I want to hide the print icon and print label from ( … ) list menu also

@ErpnextRaja @mohitchechani

I am simplifying the conditions,

Hide only print icon and label from ( … ) menu form Employee role if doc.purpose is “Transfer” or “Receipt”