I have uploaded an attachment to a Notification. I want to include it in the Message.
In the Message Example, there is a variable “comments”. It doesn’t start with “doc.”, so I guess “comments” is found within Notification, not the original Doc. Is this correct?
Hello,
finally I have made a server script on “Email Queue” doc with “After Insert” event.
This script edit “attachments” field in proper way:
files = frappe.db.get_all('File',{'attached_to_name': doc.reference_name}) #list of attachments linked to ref. doc
if len(files) > 0:
s = []
for file in files:
s.append('{"fid": "'+ file.name +'"}') #append to temp field in format: {"fid": "xxxxx"}
out = frappe.utils.comma_sep(s,'{0}, {1}', add_quotes=False) #implode to "one" row separed by comma
if len(doc.attachments) == 2: #if original att is empty => "[]"
doc.attachments = f'[{out}]'
else:
#else add to
doc.attachments = doc.attachments.replace('}]','}, '+ out + ']' ) #tady to přidávám ke zbytku
doc.save()
def add_doc_attachments(doc, method):
# restrict addition of all attachments to this particular doctype
if not doc.reference_doctype == "Payment Requisition": return
files = frappe.db.get_all('File',{'attached_to_name': doc.reference_name}) #list of attachments linked to ref. doc
if len(files) > 0:
s = []
for file in files:
s.append('{"fid": "'+ file.name +'"}') #append to temp field in format: {"fid": "xxxxx"}
out = frappe.utils.comma_sep(s,'{0}, {1}', add_quotes=False) #implode to "one" row separed by comma
if len(doc.attachments) == 2: #if original att is empty => "[]"
doc.attachments = f'[{out}]'
else:
# else add attachments
doc.attachments = doc.attachments.replace('}]','}, '+ out + ']' )
doc.save()