We use Project Management on regular basis, so for that we need to create multiple tasks and share it with multiple people and sharing with all one by one is difficult.
Can we create automation for that or may a a group of people where we just have to select that group and it will be shared with those people.?
Hi @yatharthshah,
- You can use a doctype User Group to create a group of people to assign a doc or you can also create a custom doctype to achieve the same.
- Create a custom Link field in the respective doctype to select the group.
- On save or submit(as required), Use the function
add
to assign a document to the group of people you have selected in step 2.
Example use case with doctype User Group
from frappe.desk.form.assign_to import add
def on_submit(self):
user_group = frappe.get_all("User Group Member", {'parent': <user_group>, 'parenttype': 'User Group'}, ['user'])
assign_to = [data.user for data in user_group]
add({'assign_to': assign_to, 'doctype': 'doctype', 'name': 'docname'})
Hope this helps.
Thanks!
Hello @DaizyModi ,
Thanks for your prompt reply but I would like to clarify one thing i.e., I want to share the task not assign the task.
Hi @yatharthshah ,
You need to loop over the group of users and import function add_docshare
from frappe.share import add_docshare
def on_submit(self):
user_group = frappe.get_all("User Group Member", {'parent': <user_group>, 'parenttype': 'User Group'}, ['user'])
for user in user_group:
add_docshare(<doctype>, <docname>, user=user.user, write=1)
You can pass other permissions too. Pls refer the line of code: https://github.com/frappe/frappe/blob/06ba61ff9750e6b8358c585f48180c87a851a737/frappe/share.py#L36
Use add_docshare
function as per the use case.
Thanks!
Нi!
I would like to get the values in the User Group field when a user is selected in a document field or when a user is assigned. Can you help me?