I want to assign this task to someone, but I should be able to assign it from a custom field.
I have already searched the database for this ‘Assign To’ field. It is mentioned as
_assign
, but I tried that, and it didn’t work.
Can anyone tell me how I can achieve this?
For assigning any record to any user there is an API
curl -i -X POST \ -H "Content-Type:application/json" \ -d \ '{ "assign_to_me": 0, "assign_to": ["user_id"], "description": "Automatic Assignment", "doctype": "Task", "name": "TASK-2024-03653", "bulk_assign": false, "re_assign": false }' \ 'http://dev.localhost:8000/api/method/frappe.desk.form.assign_to.add'
By using this API you can assign any task to any user from a custom_field
You can use this script
def assign_task(self):
if not self.custom_assignee:
return
previous_assignee = self.get_doc_before_save().custom_assignee
if previous_assignee == self.custom_assignee:
return
try:
add({
"assign_to_me": 0,
"assign_to": [self.custom_assignee],
"description": self.description,
"doctype": self.doctype,
"name": self.name,
"bulk_assign": False,
"re_assign": False
})
frappe.msgprint(f"Task successfully assigned to {self.custom_assignee}.")
except Exception as e:
frappe.throw(f"Failed to assign task. Error: {str(e)}")
create a Assignee field in Task doctype . write this code and add into hooks.py , call on
doc_events={
“Task”:{
“validate”:“path to .assign_task”
}}