Actually the scenario is for User 1, The Attach field will be editable and displayed. Once the form is saved by User1, User 2 will open the saved form. For user 2 the Attach field will be read only. When no file is attached by user 1 , user 2 is not able to see the field. When attached user 2 can see and it is read only.
My query is when files are not attached, why the field is going hidden to user 2.
Is there any solution?
The behavior you’re describing, where a field becomes hidden when no file is attached, is likely due to the default behavior of ERPNext when dealing with attachment fields and permissions. In ERPNext, attachment fields are often hidden by default if no file is attached to them, and this behavior can be influenced by field permissions as well.
To address your scenario where you want User 2 to see the Attach field as read-only even when no file is attached, you can follow these steps:
-
Set Field Permissions:
- Ensure that the Attach field has the correct permissions set for both User 1 and User 2.
- For User 1, allow the Attach field to be editable.
- For User 2, allow the Attach field to be read-only.
-
Make Attach Field Read-Only for User 2:
- Customize the form view for User 2 to display the Attach field as read-only, regardless of whether a file is attached or not.
Custom Script Example
Here’s an example of how you can achieve this using a custom script:
frappe.ui.form.on('Your Doctype', {
onload: function(frm) {
// Check if the current user is User 2
if (frappe.user.has_role('User 2')) {
// Make the Attach field read-only
frm.set_df_property('attach_fieldname', 'read_only', true);
}
}
});
Replace 'Your Doctype'
with the actual name of your DocType and 'attach_fieldname'
with the name of your Attach field.
Explanation
- The
onload
event triggers when the form loads.
- The script checks if the current user has the role ‘User 2’.
- If the user is User 2, it sets the Attach field to read-only, ensuring that even if no file is attached, User 2 can still see the field.
This was the code I have written already. The code is working. But when no attachments are added by user 1 means the user 2 cant able to see the field. When attachments are done by user 1 the field is displaying to user 2 and it is read only.