ImpactECS In-Depth: File Attachments and Images
This article describes incorporating file attachments and images into ImpactECS models. This functionality lends itself to a variety of use cases to expand the information captured in ImpactECS. For example, 3C Software uses file attachments to upload images of receipts into the internal time and expenses model. Another interesting way this feature is used is to upload and attach unique CAD documents or product images to product specific cost objects. It is also another option to integrate custom help documents or view archived reports.
Implementing File Attachments in a Model
When working with external files, model builders have a few different options regarding how to store this information. The initial choice to consider is to simply store the files in a shared directory on the ImpactECS server’s file system. This design, however, has several distinct disadvantages. First, when file attachments are critical, backups are necessary. When stored in this manner, model builders will need to create and manage a distinct backup procedure leading to additional maintenance and complexity. The second (and recommended) file storage option – saving the files in your model’s underlying database and leveraging the backup process already in place for the model. Here’s a sample query to create a database table for storing file attachments:
CREATE TABLE [Files]( [FileID] [int] IDENTITY(1,1) NOT NULL, [FileName] [nvarchar](255) NULL, [FileType] [nvarchar](255) NULL, [FileData] [image] NULL, [DateUploaded] [date] NULL DEFAULT GETDATE(), [UploadedBy] [nvarchar](255) NULL, CONSTRAINT [pk_Files] PRIMARY KEY CLUSTERED ([FileID])) GO
This query creates a table named “Files” with two fields that are auto-populated when new files are added (or row are inserted): FileID and DateUploaded. The FileID field provides a unique identifier for each file (independent of the file name), while the DateUploaded field indicates when the file was added. The FileData field contains the actual binary (or image) data of the file itself. Here’s a quick screen shot of what this table looks like once files are added:
Once the table is created, a simple script module can attach, view and remove files from the model. Without getting too deep in the technical details, the file attachment functionality is supported by ImpactECS’s “System.GetFileFromClient” method and the file viewing functionality is supported by the “System.OpenTempServerFile” method. More information on both methods can be found in Impact’s online help. But the GetFileFromClient method allows users to browse for a file on their local machine and upload it to the ImpactECS server. While the OpenTempServerFile method transfers a file from the ImpactECS server to the user’s machine and automatically opens it using their default application. Here are a couple of screenshots that demonstrate how this functionality is called using cell actions.
Attaching a file.
Viewing an image.
Get Started with File Attachments
Simple code changes can significantly expand the types of information available for ImpactECS model users. Not sure how to get started. As always, the 3C Software consulting team is happy to help walk you through best practices on adding file attachments. Don’t have 7.4 yet? You can learn more about the release or email us and we’ll help you get started.