sheno
March 12, 2017, 10:14am
1
Dears
Because of security so we use option like
share with
for example i need when a user make a new LEAD
this lead is automatically Shared With Aspecific person
how can i achive the automatic sharewith without let the user to press share with and choose from the list ?
1 Like
@sheno ,
You will need to write a server / client script to achieve the auto share functionality. On documents validate method you can share the document with a specific user.
To share the document you can use the add
method.
e.g.
server script
from frappe.share import add
add(doc.doctype, doc.name, user, read, write, share, everyone)
client script
frappe.call({
method: "frappe.share.call",
args: {
doctype: "Lead",
name: "Lead-00001",
user: "user name"
read: 1,
write: 1,
share: 0,
everyone: 0
},
callback(r) {
if(r.message) {
// document is shared with user
}
}
})
Thanks,
Makarand
3 Likes
Can I make this script as Custom Script!
makarand_b:
frappe.call({ method: āfrappe.share.callā, args: { doctype: āLeadā, name: āLead-00001ā, user: āuser nameā read: 1, write: 1, share: 0, everyone: 0 }, callback(r) { if(r.message) { // document is shared with user } } })
Thanks,
its not working. Showing error. Please advise
Have you tried the auto assignment feature? Which version are you on?
1 Like
use this in custom script
frappe.call({
method: āfrappe.share.callā,
args: {
doctype: āLeadā,
name: doc.name,
user: frappe.session.user,
read: 1,
write: 1,
share: 0,
everyone: 0
},
callback(r) {
if(r.message) {
// document is shared with user
}
}
})
1 Like
alkuhlani:
frappe.call({
method: āfrappe.share.callā,
args: {
doctype: āLeadā,
name: doc.name,
user: frappe.session.user,
read: 1,
write: 1,
share: 0,
everyone: 0
},
callbackĀ® {
if(r.message) {
// document is shared with user
}
}
})
@alkuhlani Thank you. i need to share the events created by the employees to be share with the Manager with Auto Share, while i am adding this code ,getting error. Kindly advice
How to use this in server script?
add(āUser Remaining Subscription planā, āaa@mas.com-2022-10-30ā, āwork.masoudhosseini@gmail.comaaā, write=1, share=1)
Nyikal
December 6, 2022, 1:46pm
11
Where can I find this feature?
Hello
I tried the Server Script:
frappe.share.add_docshare(doc.doctype,doc.name,doc.user,1,1,0,0)
It gave me an error message: (TypeError: āNoneTypeā object is not callable)
I traced the error and I found that the (frappe.share.add_docshare) is the āNoneTypeā
Please advise on how to fix this error
I am using Version 14
try this, iām using this to share the doc when itās submitted
def on_submit(self):
frappe.share.add_docshare(
self.doctype, self.name, self.assign_to, write=1, submit=1, share=1, flags={"ignore_share_permission": True}
)```