How to Restrict User to update only 1 record in a doctype

Hi Team,

I have to collect employee family member details for our health benefit program. However in when i am giving the rights to update the records. It is allowing the employee to more records. Is there any possibility in frappe to restrict the user to update only 1 record.

You can use Frappe’s built-in User Permissions to ensure that employees can only access records related to themselves or their own employee profile.

1 Like

U can Add Specific Role Doctype to If only creator role if the user have create that record then select the role permission to if only creator check box tick if user have not create that record then u have write the user permission for the all user to apply all doctype and specific doctype also

Role Permission :

1 Like

Thanks for your suggestions , however my issue is that, only the employee can create single record . In the doctype it is giving option to create multiple records.
So i want to restrict it.

@bandarivijay you can do it by using server script

employee_id=frappe.db.get_value("Employee",{'user_id:frappe.session.user'},'name')
if employee_id:
  if frappe.db.exists('Doctype Name',{'owner':frappe.session.user}
          frappe.throw('Record is already created by this employee')
1 Like

@Jeel Thanks for the suggestion.

I have added a workflow to my doctype where the employee will enter the details and then HR user will validate it approve or Reject.

However by using below mentioned code i am unable to achieve desired results.

My criteria is if HR user rejects the request then user can able to add new request .

I have 2 scenarios

Scenario 1 the employee can re-add after HR employee reject the request.

Scenario 2 the employee should approve or reject the request.

class EmployeeHealthBenefit(Document):

def validate(self):
	frappe.msgprint(f"status: {self.status}")
	if 'HR User' in frappe.get_roles():
		pass
	else:
		employee_id=frappe.db.get_value("Employee",{'user_id:frappe.session.user'},'name')
		if employee_id:
			frappe.msgprint("employee exists")
			if frappe.db.exists('Employee Health Benefit',{'owner':frappe.session.user}):
				frappe.msgprint("Employee Health Benefit exists")
				all_user_docs = frappe.get_all('Employee Health Benefit',filters={'owner':frappe.session.user})
				frappe.msgprint(f"all_user_docs: {all_user_docs}")
				for doc in all_user_docs:
					if doc.status != 3 or doc.workflow_state == "Draft":
						frappe.msgprint("doc.status is not 3")
						frappe.throw('Record is already created by this employee')