A Smart Way to Export Field Contents - Part 2

By Gearbox Solutions | 11/12/2015

We love sometimes like Selector Connector

Since the initial news of this new technique from Todd Geist and Jason Young's smashing session at DevCon this year, we've been incorporating it into most of our solutions.

If you haven't seen Part 1 discussing how we improved the ability to download files from container fields with one script, check it out.

Sometimes "good enough" is never enough. I thought we had moved on, but I was reminded that I had designed this particular large project to manage all files (everything form creative briefs, spreadsheets, PDFs, lo-res comps, etc.) in one table and my colleague knew we were using Selector Connector.

Why don't we just leverage Selector Connector and pass the ID of the file record to SELECTOR and there's your target?

He was right... We avoided premature optimization and then iterated as a team to come up with something that was simple to implement, simple to use, and then moved on. Below is the final script.

What do you think?

[saveFile ( id )]
# . . . . . . . Gearbox Solutions
# . . . . . . . created on - 11.10.2015
# . . . . . . . created by - mhl
# . . . . . . . purpose - export contents of container to 'Downloads' folder
# . . . . . . . updates...
# . . . . . . . 11.11.2015 - mhl - rohit - write files to a global so we can export without hardcoding 'Export Field Contents'
# . . . . . . . 11.12.2015 - mhl - Marty suggested leveraging SelectorConnector
#  set vars
Set Variable [ $vars ; Value: #Assign ( Get( ScriptParameter ) ) ] 
#  
# 11.12.2015 4:22pm - since all container fields/'files' are saved in a single "files" table, get the ID and use SelectorConnector
#  
# SELECTOR
Set Field [ SELECTOR::id_FILE ; $id ] 
Set Variable [ $filename ; Value: GetContainerAttribute ( SEL.file::file ; "filename" ) ] 
Set Variable [ $filepath ; Value: Substitute(Get(DesktopPath);"Desktop";"Downloads") & $filename ] 
# now export from ONE place!
Export Field Contents [ SEL.file::file ; "$filepath" ; Automatically open ] 
Exit Script [ Result: 1 ] 
#  
# 11.11.2015 8:52pm - we're going to try a technique suggested by Rohit to use a global so we don't have to go through what is below...
#  
# copy into global
Set Field [ globals::FILE_TEMP_CONTAINER ; Evaluate ( $field ) ] 
# now export from ONE place!
Export Field Contents [ globals::FILE_TEMP_CONTAINER ; "$filepath" ; Automatically open ] 
Exit Script [ Result: 1 ] 
# have to hard code field :(
If [ $entity = "approvals" ] 
    Export Field Contents [ SEL.approval_versions::file ; "$filepath" ; Automatically open ] 
Else If [ $entity = "pro.files" ] 
    Export Field Contents [ pro.files::file ; "$filepath" ; Automatically open ] 
End If
Categories: FileMaker