Document assignment using pthyon server side script

how to assign a document to user not from frontend, not using assignment rule as I have to apply some logic to find the user to whom I need to assign the document, I want it from server side script. can someone know how to do this?

  • add a custom field and set assigned user using script
  • setup assignment rule to use this field for assignment
1 Like

in assignment rule there is no option of a field to assign user

There is.

image

1 Like

Got it. Thanks

How would we do this if we needed to assign multiple users?
Table MultiSelect fields are not shown in the “Field” dropdown in the “Assign To Users” section.

HI @meichthys:

Can’t do it with assignment rule.
Actually, assignment is a related ToDo. So, you can manage it with some scripting.

In this example I created a custom multiselect field for add users (custom_assigned_users) on Sales Order doctype.

This server script (before_save), will allocate an assignment for each user on multiselect, linked to the Sales Order and due_date in 10 days.

for u in doc.custom_assigned_users:

    new_assign = frappe.get_doc(
    {"doctype": "ToDo",
    "allocated_to": u.name,
    "reference_type": "Sales Order",
    "reference_name": doc.name,
    "description": "There is a new sales order for you ...",
    "priority": "Medium",
    "date": frappe.utils.add_to_date(days=10, as_string=True),
    "assigned_by": frappe.session.user
}).insert(ignore_permissions=True)

Hope this helps.