Rich Text - Formula to Save As attachment
I'm leaving this here in case I come looking for how it all works after I forget. I couldn't find anything that actually talks about this UX so here's my version.
Recently we found out there is a setting at Quickbase farms where an attachment type field that contains a PDF can change the expected behavior from open the PDF in a browser tab to opening the "Save As" dialog.
The differences in behavior can be regarded by Users as extra work. ie "I just want to look at the PDF, why do I have to download it first?" and conversely "I want to save this file, why is it appearing my my browser so I have to download it?" yeah we have both too.
First ask QB to set the setting to your preference. In our case it was open in a tab to view over force Save As dialog. This handles the majority of use cases and exposes the alternate requirements. Below is how we solve the alternative requirements using Rich Text - Formula fields, now with Logic! What I mean by logic is if there isn't an attachment, don't let the button try to open anything. BTW there are A LOT of better options here.
// The e36 part of the $url variable is the fid of the attachment field you want to open. v0 is the version (we set ours to 1), so you can open older versions (never got it to work)
//The [styleView] variable is a Quickbase variable. Located in the App properties, this is where we inline style. We name the variables [style<somehitng>] and then call the style from the formula. This means we create one style for the App and then that style appears on every button in every table. If we want to change it, we change it in one place and it updates everywhere. We also sync our styles to all our Apps using API so we only have to update the style in one App to update every button in the realm. Just in case you were wondering.
//Formula Rich Text field data Type; hide the field name, uncheck searchable.
//logic, If the file attachment field is blank then the URL is blank, otherwise the URL is the link to the Attachment field.
// this part below goes in the Rich Text - Formula field.
var text btnName = "Save As";
var text url = URLRoot() & "up/" & [Record ID#] & "/a/r" & [attachment] & "/e36/v0";
var text style = [styleView];
var text title = "";
//*****DO NOT EDIT BELOW THIS LINE*****
//HTML button
If( [attachment] = "", "","< a class='OpenAsPopup' data-height=600 data-width=600 title=\"" & $title & "\" style =\"" & $style & "\"href=" & $url & "download=" & [attachment File] & ">" & $btnName & "</a>")