Attachments in Notification

Hello hello,

I have uploaded an attachment to a Notification. I want to include it in the Message.

Screenshot 2022-07-15 at 10.07.29 AM
Screenshot 2022-07-15 at 10.07.22 AM

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?

From this hint I looked for it by editing the Notification DocType. Can’t find it.

The question is, how do I include Notification Attachments in Notification Message? How do I reference the Attachments?

Thanks!

Found out that the Attachment can be found in File Manager.

Now I need to figure out how to reference any Attachments in File Manager within Notification’s Message area.

Hi @charleslcso ,
did you resolve it, please?
Jirka

Same question…

Yes i have same question

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()

I hope it helps.
Jiri Sir

2 Likes

Thank you very much for this @Jiri_Sir

Here’s how I did mine with a condition to make sure it applies to the specific doctype:

doc_events = {
	"Email Queue": {
		"after_insert": "my_app.app.add_doc_attachments"
	}
}

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()

1 Like