Linking to Images
In a similar way to how we can link a transaction to the underlying form in UniFi, we can also link directly to a scanned image stored in an attachment field using another custom expression.
As with the linking to a transaction, we need to create a custom expression, however this time it will be based on the field that contains the image you want to drill to. Drag that across into your report from the list of available fields, and from the 'Change to aggregate column' menu select 'Custom Expression'. This will change the expression column to something like:
demo.purchase_invoice.scanned_invoice_attachment
This is essentially the customer account followed by the app id and then the field id of the image field. We now need to incorporate this into a URL that will link to the item. The format of this URL is:
https://<customer_account\>.unifiplatform.com/permalink/file?key=<customer account.app id.field id\>
So we can use the SQL 'CONCAT' function as with linking to forms to generate a hyperlink. One further consideration is that on the underlying database, image names are stored within square brackets so we need to remove these from the URL. This can be done using the SQL 'REPLACE' function, so the final link will look something like:
CONCAT('<a href="https://demo.unifiplatform.com/permalink/file?key=', REPLACE(REPLACE(demo.purchase_invoice.scanned_invoice_attachment, '["', ''), '"]', ''), '" target="_blank">Link</a>')
You can copy and paste this into a text editor and do the following replacements:
- Replace each instance of 'demo' with your customer account
- Replace demo.purchase_invoice.scanned_invoice_attachment with the custom expression you created.
You can now take the amended custom expression and paste it back into the quick reports column, replacing the existing expression. When the report is now run it should produce a clickable link to the stored image.
You can combine this with the 'case' function to only show the link if an image file exists. This works in the following format:
case when <condition> then <true> else <false> end
So we could construct something like:
case when demo.purchase_invoice.scanned_invoice_attachment <> '\[]' then CONCAT(...) else '' end
You can use similar techniques to link to images and transactions from other systems that have the ability to form a custom URL as long as all the relevant data is stored somewhere in that system.