Add attachment in compose email view.

I have extend compose.js file. In this file I want to add attachment. For attachment I have create custom endpoint and in this endpoint I'm getting pdf row data. I can convert this row data and tried to attached as attachment but it's not work. 

compose.js code.

fetchAndAttachPDF: function () {
    var self = this;
    var email = this.model;

    app.api.call('GET', app.api.buildURL('ComposeEmailAttachPdfApi/getBase64'), null, {
        success: function (response) {
            var filename = response.filename || 'Report.pdf';
            var base64 = response.base64data;
            var mimeType = response.mimeType || 'application/pdf';

            try {
                // Convert base64 to Blob
                var byteCharacters = atob(base64);
                var byteNumbers = new Array(byteCharacters.length);
                for (var i = 0; i < byteCharacters.length; i++) {
                    byteNumbers[i] = byteCharacters.charCodeAt(i);
                }
                var byteArray = new Uint8Array(byteNumbers);
                var fileBlob = new Blob([byteArray], { type: mimeType });

                // Create a File object (optional fallback name)
                var file = new File([fileBlob], filename, { type: mimeType });

                // Prepare FormData
                var formData = new FormData();
                formData.append('filename', file); // Important: use `filename` key here

                // Upload to temporary Notes file endpoint
                var uploadUrl = app.api.buildURL('Notes/temp/file/filename', null, {
                    delete_if_fails: true,
                    platform: 'base'
                });
				
				console.log('formData');
				console.log(formData);
                app.api.call('create', uploadUrl, formData, {
                    processData: false,
                    contentType: false,
                    success: function (note) {
                        // Attach the uploaded note to the email
                        email.get('attachments_collection').add({
                            _link: 'attachments',
                            name: note.name,
                            filename: note.filename,
                            id: note.id,
                            mime_type: note.file_mime_type
                        });

                        app.alert.show('pdf-attach-success', {
                            level: 'success',
                            messages: 'PDF successfully attached.',
                            autoClose: true
                        });
                    },
                    error: function (err) {
                        console.error('Upload failed', err);
                        app.alert.show('pdf-attach-fail', {
                            level: 'error',
                            messages: 'PDF upload failed.',
                            autoClose: true
                        });
                    }
                });
            } catch (e) {
                console.error('Base64 decode error:', e);
                app.alert.show('pdf-process-fail', {
                    level: 'error',
                    messages: 'Error processing PDF content.',
                    autoClose: true
                });
            }
        },
        error: function (err) {
            console.error('PDF fetch failed', err);
            app.alert.show('pdf-fetch-fail', {
                level: 'error',
                messages: 'Failed to fetch PDF.',
                autoClose: true
            });
        }
    });
},

Parents
  • In the Emails module you can attach a document stored in the Sugar's Documents module:

    1. Compose the Email: Start by composing your email in SugarCRM.
    2. Access the Attachment Menu: Locate the "Attachment" option in the email editor.
    3. Select "Sugar Document": Choose the "Sugar Document" option from the Attachment menu. This will open a search screen allowing you to find documents within SugarCRM.
    4. Search for the Document: Use the search interface to locate the specific document you want to attach.
    5. Select and Attach: Once you've found the document, select it, and it will be added as an attachment to your email.
    6. Send the Email: Complete your email and send it as usual. 
    would that work for your scenario?
    FrancescaS
Reply
  • In the Emails module you can attach a document stored in the Sugar's Documents module:

    1. Compose the Email: Start by composing your email in SugarCRM.
    2. Access the Attachment Menu: Locate the "Attachment" option in the email editor.
    3. Select "Sugar Document": Choose the "Sugar Document" option from the Attachment menu. This will open a search screen allowing you to find documents within SugarCRM.
    4. Search for the Document: Use the search interface to locate the specific document you want to attach.
    5. Select and Attach: Once you've found the document, select it, and it will be added as an attachment to your email.
    6. Send the Email: Complete your email and send it as usual. 
    would that work for your scenario?
    FrancescaS
Children
No Data