Print multiple attachments

  • 2
  • Question
  • Updated 3 years ago
  • Answered
I know that I can access an attachment by using "/servlet/servlet.FileDownload?file={{Id}}". Rob seems to say in this thread that you can put this inside of a img tag, to show multiple attachments on a single page. I have been experimenting with this, and it doesn't seem to be working for me (not getting anything) . I have tried the img, iframe, embed, and object tag, and they all don't display as nicely and cleanly as previewing the attachment. I would like to know if there is a good way to display an attachment as its full size, using a template.  

Also, assuming it is possible to display this, I would like to be able to print multiple attachments at one time. So assuming I have templates displaying Attachment 1,2,3,4 and 5, I would like to be able to print the entire page and get all 5 of the attachments printed in one print job. Is this possible??? Any ideas???
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb

Posted 3 years ago

  • 2
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
The only kind of attachments I was able to populate were images and PDF's.  I used some JS code to render images in an IMG tag, and PDF's in an iFrame.  

Quick thinking suggested that these were about the only attachment types that could be reliably rendered in browser, and it satisfied the customer demand. 

This was in a client org about 2 years ago - so its lost and fuzzy.  
Photo of Chelsea Curtis

Chelsea Curtis

  • 1,300 Points 1k badge 2x thumb
I think we were that client. Our use case was a need to see multiple attachments for a specific record on the same page. Rob built out a page with record detail on the left and a preview of the attachments on the right.

There is a table on the right for the Attachments model and a field that is custom rendered with the following javascript:

var $ = skuid.$;var field = arguments[0];
var value = arguments[1];
var row = field.row;
var id = row.Id;

var ext = value.slice(-3);
//console.log(ext);
var text;

if (ext === "jpg") {
    text = "<A href = '/servlet/servlet.FileDownload?file="
            +id
            +"' target='blank'>"
            +value
            +"</A><BR><Img width='100%' src='/servlet/servlet.FileDownload?file="
            +id
            +"' />";
   }
else 
        {   if (ext === "pdf"){
            text = "<A href = '/servlet/servlet.FileDownload?file="
                +id
                +"' target='blank'>"
                +value
                +"</A><BR><iframe id='myframe' src='/servlet/servlet.FileDownload?file=" 
                +id
                +"' width='100%' height='600px' overflow='scroll'/><BR>";
                }

        else {text = "<A href = '/"
            +id
            +"'>Unknown File Type  "
            +value
            +" - Link to Detail</A>";
        }
    }


//console.log(text);            
            
field.element.append(text);


We only needed the view for images and pdfs for this particular use case. It would be interesting to know if it's possible for word docs. We would also be interested in a print all function for all previewed attachments.

Hope this helps, Moshe.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
HA! Thanks Chelsea.  I appreciate you sharing the work I did for you guys.  I hope your process is still running successfully.   Word docs are tough though. Mostly depends on the browser being used and how the OS is set up to handle those files. 
Photo of Chelsea Curtis

Chelsea Curtis

  • 1,300 Points 1k badge 2x thumb
Still working great! That process is what made us choose Skuid:) We are very happy we did.
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Thanks Chelsea and Rob, do either one of you remember what field the field renderer/javascript is running on? What field on the attachment object does the snippet run on?
Photo of Chelsea Curtis

Chelsea Curtis

  • 1,300 Points 1k badge 2x thumb
It's the Name field on the attachment object.
Photo of Jack Sanford

Jack Sanford, Champion

  • 8,322 Points 5k badge 2x thumb
Any luck printing from this? I'm looking for a way to download multiple attachments. 
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
This will print the contents of the browser window, but I don't think that is what you are after. 
Photo of Jack Sanford

Jack Sanford, Champion

  • 8,322 Points 5k badge 2x thumb
Nope, I think I've got a solution through Conga though. Thanks!