REQUEST A DEMO

Customizing the Clarify Attachment Form (form 1006)

I recently had to do some modifications to the attachment form in Clarify (form 1006). This is one of those old-school forms that doesn’t always behave very well with ClearBasic. This post captures a few of my findings and learnings.

FILELIST Double-Click

 

One of the things I wanted to do was to intercept the double-click action on the FILELIST control, which happens when a user double-clicks a file to Open it.

 

Plan A: some simple Clearbasic code

Sub FILELIST_DblClick()
If FileValidation = True Then
Me.DoDefault
Else
App.MsgBox “Not authorized”
End If
End Sub

 

Looks simple right? But it doesn’t work. Even if the Me.DoDefault code isn’t ever called, the file is still opened. So if the validation failed, the user would get the message box saying “Not authorized”,  and then the file would be opened. No bueno.

 

I tried everything I could think of, but I couldn’t prevent the file from being opened. I found an old forum post with the same findings.

 

Plan B: Change the FILELIST control so that it’s no longer a fancy file renderer with drag and drop capabilities, and just make it a plain ol’ listbox. I did this by deleting the existing control, then adding a new listbox with the same name (FILELIST), and the same source and destination contextual objects. I think the same thing would work by changing the flags on that control_db record from 32768 to 0.

 

Now I am able to trap the double-click event on that textbox.

 

I did lose the ability to drag and drop files onto that control now, but that didn’t matter for my scenario (and I have a hunch that no one uses this anyway).

 

Here’s what the baseline attachment form looks like, with a “fancy” listbox for files:

attachment_baseline

 

And now after changing it to a non-fancy listbox:

 

attachments_better

 

I actually prefer this, as I can see more than just a couple of files at a time.

 

But, the filelist listbox now showed a full file path and file name for each of the attachments. I didn’t like that.

Make it Better

 

Lets get rid of the full path in the listbox.

 

A little ClearBasic code:

Sub ReplaceFilePathsWithJustFileName()
Dim allFiles As List
Dim i As Integer
Dim fileAndPath As String
Dim fileName As String
Dim n As Integer

cobj_doc_list.GetContents allFiles

For i = 0 To allFiles.Count – 1
fileAndPath = allFiles.ItemByIndex(i)
fileName = GetFileNameFromFileAndPath(fileAndPath)
allFiles.ReplaceByIndex i, fileName
Next i
cobj_doc_list.Fill allFiles
End Sub

Sub Form_Load()
Me.DoDefault
Call ReplaceFilePathsWithJustFileName()
End Sub

Sub ADD_BTN_Click()
Me.DoDefault
Call ReplaceFilePathsWithJustFileName()
End Sub

Sub REPLACE_BTN_Click()
Me.DoDefault
Call ReplaceFilePathsWithJustFileName()
End Sub

 

And now our listbox of files looks like:

attachments_no_paths

 

Cleaner. I like it.

Default the Attachment Name

 

One of my annoyances with that form is that when you browse and pick a file to be attached, you also have to enter an attachment name. I always wish that this had some sort of smart default, such as defaulting to the name of the file (without the path).

 

Since I was knee deep in that form, I tried to give it a try.

 

I added a click handler for the Browse button so that it gets the full file and path, gets just the file name out of that, and then puts that file name into the attachment name textbox:

Sub FILE_BTN_Click()
Dim fileAndPath As String
Dim fileName As String

Me.DoDefault

fileAndPath = FILE.Value
fileName = GetFileNameFromFileAndPath(fileAndPath)
Ctl_Name.Value = fileName
End Sub

 

And a little helper function for extracting just the filename:

Function GetFileNameFromFileAndPath(fileAndPath As String) As String
Dim n As Integer
n = ItemCount(fileAndPath,”\”)
GetFileNameFromFileAndPath = Item$(fileAndPath,n, n + 1,”\”)
End Function

 

So now, when you browse and pick a file, the Attachment Name will be defaulted to the filename. Sweet.

Download File Attachments via HTTP

 

An additional enhancement that I was working on was the ability to download a file attachment via HTTP. In a customer-specific scenario, we were uploading attachments via a Dovetail web application (Dovetail AgentLite), so they get stored on a common server, and we can download them via a URL.

I added a readonly URL textbox to the form (which was super helpful when developing).

 

my_attachment

 

When a file is clicked in the listbox, we want to build the proper URL, and fill that into the textbox via the contextual object.

 

I’m using our Dovetail Mobile as a web app for serving up that file. If desired, you could also serve it up just via your web server serving up a static file, without needing a Dovetail web app at all.

 

Const Base_Dovetail_URL = “http://localhost/mobiledev/Attachments/Download/”

Sub FILELIST_Click()
Me.DoDefault
Cobj_url.Fill BuildURL()
End Sub

Function BuildURL() As String
Dim recDocInst As Record
COBJ_doc_inst.GetContents recDocInst

BuildUrl = Base_Dovetail_URL & CStr(recDocInst.GetField(“objid”))
End Function

Open that file

 

And finally, a little code to open the file URL using the user’s browser.

Sub OpenURL(url)
Dim taskID As Variant
taskID = Shell(“explorer.exe ” & url)
End Sub
Sub EDIT_BTN_Click() ‘Note: This is the “Open” button
Dim url As String
url = BuildUrl()

OpenURL(url)
End Sub

What about file uploads?

 

In the specific customer scenario I was working on, they aren’t uploading file attachments via the Clarify Client – just by Dovetail. So I was able to simply disable the Browse, Add, Replace, and Delete buttons.

 

Uploading files to a common location is an interesting topic – perhaps for a future blog post.

Summary

 

The attachment form is certainly a tricky form to customize. Hopefully some of my experience will help should you have to customize this form yourself.