Tuesday, January 13, 2009

FILEMAKER: Looping Script To Clean Email Addresses

From Dwayne Wright - Certified FileMaker 9 Developer
WEB: www.dwaynewright.com
EMAIL: info@dwaynewright.com
TWITTER: dwaynewright

CHAPTER XX: Scripting Loops

This article is a piece of a larger collection of articles on a proof of concept file I'm doing with the 360Works email plug-in. I'll include some links below for the other articles. As I was building this part of the example file, I knew I'd be doing some portal work that some folks might not have seen before. So I thought I'd document it here in the FileMaker Portals Explored Blog. Here are the previous links ...

This article is a piece of a larger collection of articles on a proof of concept file I'm doing with the 360Works email plug-in. I'll include some links below for the other articles. As I was building this part of the example file, I knew I'd be doing some portal work that some folks might not have seen before. So I thought I'd document it here in the FileMaker Portals Explored Blog. Here are the previous links ...

External Functions Registering Your Plug-in
Custom Function - Name On Email
A Friday Afternoon With The 360Works Email Plug-In
Constant Relationship Portals And Tab Panels

Well, sometimes the proof of concept files come in real handy when you notice that you missed something. I had written a custom function to build my filtered portals by account. I hadn't taken into account that a TO address may have multiple accounts, so I need to tweak that to show the multiple accounts in a multiple line match field. In fact, I will probably want to have the accounts show not only the To address but the CC and BCC addresses as well.

Now, I'm absolutely horrible at groking recursion in custom functions. It has never made sense to me quickly and I've never seen a resource that does a very good at describing the process in a way that sticks. So I will come back to that later, right now I'll just go ahead and build a looping script to take care of my needs. Now that FileMaker 10 has script triggers and script can be copied and pasted between files, I wonder if I will forego using custom functions as much as I have in the past.

Anyway, back to the task at hand. I want to have a multiple line key field that has every possible account that exists in a to, cc or bcc field. At first, I created a script variable to take care of this but multiple line variables that are being parsed are kind of hard to see in the Data Viewer as they are being parsed. So I downshifted yet again to my old friend the global field. This way I can watch my script parse each field as it runs.

My final script looks something like this ...

Set Field [ MESSAGES::EmailNamesGlobal; If ( not IsEmpty(MESSAGES::to) ; MESSAGES::to & "¶" ; "" ) &
If ( not IsEmpty(MESSAGES::cc) ; MESSAGES::cc & "¶" ; "" ) &
If ( not IsEmpty(MESSAGES::bcc) ; MESSAGES::bcc ; "" ) ]
Set Field [ MESSAGES::emailAccount; EmailName ( RightValues ( MESSAGES::EmailNamesGlobal ; 1 ) ) ]
Loop
Set Field [ MESSAGES::EmailNamesGlobal; LeftValues ( MESSAGES::EmailNamesGlobal ; ValueCount ( MESSAGES::
EmailNamesGlobal ) -1) ]
Set Field [ MESSAGES::emailAccount; MESSAGES::emailAccount & "¶" & EmailName ( RightValues ( MESSAGES::
EmailNamesGlobal ; 1 ) ) ]
Exit Loop If [ IsEmpty(MESSAGES::EmailNamesGlobal) ]
End Loop

Now someday I really want to come back to doing this via a custom function. I should be able to have the calculation return the values I needed. Custom function developer tend to communicate in some sort of short hand that bewilders me.
=
More info about the author and FileMaker in general, contact me at info@dwaynewright.com.

© 2008 - Dwayne Wright - dwaynewright.com

The material on this document is offered AS IS. There is NO REPRESENTATION OR WARRANTY, expressed or implied, nor does any other contributor to this document. WARRANTIES OF MERCHANT ABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY DISCLAIMED. Consequential and incidental damages are expressly excluded. FileMaker Pro is the registered trademark of FileMaker Inc.

ADVERTISEMENT ==============================
Looking for a robust FileMaker CRM template to manage your business? Check out the InBizness product line at http://www.dwaynewright.com/solutions.html.