<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The FileMaker Collective &#187; Advanced Techniques</title>
	<atom:link href="http://fmcollective.com/category/advanced-techniques/feed/" rel="self" type="application/rss+xml" />
	<link>http://fmcollective.com</link>
	<description>Syndicating the best FileMaker blogs</description>
	<lastBuildDate>Tue, 27 Jul 2010 15:42:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Global Variables for List Selections</title>
		<link>http://sixfriedrice.com/wp/using-global-variables-for-list-selections/</link>
		<comments>http://sixfriedrice.com/wp/using-global-variables-for-list-selections/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 20:36:54 +0000</pubDate>
		<dc:creator>Daniel Antunes</dc:creator>
				<category><![CDATA[Advanced Techniques]]></category>
		<category><![CDATA[S.F.R]]></category>
		<category><![CDATA[Syndicated]]></category>

		<guid isPermaLink="false">http://sixfriedrice.com/wp/?p=233</guid>
		<description><![CDATA[A funny thing happened while I was stumped over the question of how to allow one of our clients to select and deselect multiple items in a list.  Multiple people would be using the list at the same time.  I was struck by the fact that I&#8217;ve been making something more complicated than it needs [...]]]></description>
			<content:encoded><![CDATA[<p>A funny thing happened while I was stumped over the question of how to allow one of our clients to select and deselect multiple items in a list.  Multiple people would be using the list at the same time.  I was struck by the fact that I&#8217;ve been making something more complicated than it needs to be for as long as I&#8217;ve been working with Filemaker.  After toying with various methods which included adding fields to the records in the list, join tables, global fields and horribly convoluted scripting it occurred to me that you can actually write a relatively simple custom function to handle it all.  It will add or subtract a value from a list that is stored in a global variable and then simply do some conditional formatting to highlight the selected items in the list.  No additional fields or scripting are needed, the global variable is session specific and once you are done you&#8217;ve got your list of data ready to go as is.</p>

<p><span id="more-233"></span>Here are all the components of this process and how they fit together:</p>

<p>AddOrRemoveFromList(list, value) &#8211; The custom function that will maintain the values in the list for you.</p>

<p>$$selectedItems &#8211; The global variable that stores the list I want to operate against.</p>

<p>Selected Item &#8211; The actual record that you are adding to the list.</p>

<p>First I&#8217;d like to explain the custom function.  Basically, that function checks a list that you the value you pass in.  If the function finds that value, it removes the value and returns the new list sans value.  If it doesn&#8217;t find the value, it returns to you the list with the value appended to the end of it.  Here is the what AddOrRemoveFromList(value, theList) contains:</p>

<p>let(</p>

<p>[newList = Substitute(¶ &amp; theList &amp; ¶, ¶ &amp; value &amp; ¶, ¶)];</p>

<p>if( PatternCount( ¶ &amp; theList &amp; ¶; ¶ &amp; value &amp; ¶) = 1 ; Middle(newList, 2, length(newList) &#8211; 2); theList &amp; if(not isempty(theList); ¶) &amp; value)</p>

<p>)</p>

<p>The reason for all those extra ¶&#8217;s is for encapsulation and searching.  When you think about what a list actually is, it turns into this:  apple¶orange¶pear¶applejuice.  If you want to search that list for apple right now you would be editing both the values apple and applejuice.  To get around that we put an extra ¶ before the first entry in the list and after the last entry so our list now looks like ¶apple¶orange¶pear¶applejuice¶.  So, if we now search for ¶apple¶ we would only be working with the actual apple value.  To get the correct list format returned after that you just need to use the middle function to strip the first and last ¶ from the list.</p>

<p>So, we now have a custom function that will handle adding and removing values from a list.  The only thing we have to do to make a selection is to say where we want to store the list.  Using a global variable has the advantage of being easily accessible and being completely separated from your data structure, so you don&#8217;t need any additional fields or records to keep track of what the user wants selected.  So, if you choose to use a global variable, the only step you need to take is to set the variable $$selectedItems using the custom function.  Here&#8217;s what that step looks like:</p>

<p><a title="Setting the Global Variable" href="http://sixfriedrice.com/wp/wp-content/uploads/2009/01/list-management-script.jpg"><img src="http://sixfriedrice.com/wp/wp-content/uploads/2009/01/list-management-script.jpg" alt="Setting the Global Variable" /></a></p>

<p>If you are unformiliar with our parameter passing system, please take a look at this.  So, we now have the selected items being added to the desired list automatically.  So, let&#8217;s let the user see what they&#8217;ve selected.  Using conditional formatting we&#8217;ll just apply that same list checking we used in the custom function.  The formula should be:</p>

<p>PatternCount( ¶ &amp; $$selectedItems &amp; ¶; ¶ &amp; item &amp; ¶) = 1</p>

<p>&#8220;item&#8221; in the above example should be whatever you passed into the list.  No</p>
]]></content:encoded>
			<wfw:commentRss>http://sixfriedrice.com/wp/using-global-variables-for-list-selections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script Triggers: Filter as You Type</title>
		<link>http://sixfriedrice.com/wp/script-triggers-filter-as-you-type/</link>
		<comments>http://sixfriedrice.com/wp/script-triggers-filter-as-you-type/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 18:33:33 +0000</pubDate>
		<dc:creator>Geoff Coffey</dc:creator>
				<category><![CDATA[Advanced Techniques]]></category>
		<category><![CDATA[FileMaker 10 Tips]]></category>
		<category><![CDATA[S.F.R]]></category>
		<category><![CDATA[Syndicated]]></category>

		<guid isPermaLink="false">http://sixfriedrice.com/wp/script-triggers-filter-as-you-type/</guid>
		<description><![CDATA[For years, FileMaker developers have been devising various filter techniques. The idea is that you type all or part of a name, part number, description, etc… and a list of results filters down to show relevant matches. As handy as these techniques are, they always stop just short of perfect because, before FileMaker 10, you [...]]]></description>
			<content:encoded><![CDATA[<p>For years, FileMaker developers have been devising various <em>filter</em> techniques. The idea is that you type all or part of a name, part number, description, etc… and a list of results filters down to show relevant matches. As handy as these techniques are, they always stop just short of perfect because, before FileMaker 10, you had to <em>exit the field</em> before the filter would take effect. Using FileMaker 10&#8217;s powerful Script Triggers, you can make the impact of your filtering more immediate.</p>

<p><span id="more-279"></span></p>

<blockquote>
  <p>Note: We&#8217;ve never done this before, but the idea, scripts, and sample file for this technique come directly from FileMaker luminary and Six Fried Rice reader David Graham of <a href="http://bittailor.com" title="Bit Tailor: Software with a Perfect Fit">Bit Tailor</a>. We&#8217;re publishing it here (with David&#8217;s permission) because it is an excellent example of Script Triggers solving an age-old problem in an elegant way.</p>
</blockquote>

<p>There are as many ways to filter lists in FileMaker as there are developers implementing it. The beauty of this technique is that it doesn&#8217;t matter if you prefer exploded keys and filtered portals, aggregate text fields and a find, or (my personal favorite) scripted multi-request finds. Whatever you want, when it is fast, clean filtering you&#8217;re after, it is <em>always</em> better if the results appear as you type. This sort of thing was essentially impossible with FileMaker 9. Once a user started entering data in a field, you were hands-off until they finished.</p>

<p>Some people dreamed up horrifying solutions with looping scripts and all manner of wackiness. These techniques, in my opinion, <em>never</em> worked well. Consequently, we were always resigned to the &#8220;press Enter when you&#8217;re done&#8221; model. But when the results appear as you type, the user gets immediate feedback, only needs to go as far as necessary to get the result she wants, and doesn&#8217;t have to click back into the field to correct or make a change. So it is clearly a better model. See for yourself:</p>

<p align="center"><script language="JavaScript" type="text/javascript">
QT_WriteOBJECT_XHTML (
  "http://sixfriedrice.com/wp/wp-content/uploads/2009/01/modify-filter.mov", "456", "385", "", "autoplay", "false"
);
</script></p>

<p>David&#8217;s technique relies on the handy <code>OnObjectModify</code> trigger on the filter field to kick off a script every time the field changes. This includes:</p>

<ul>
<li>When you add a single letter to the field by typing a key.</li>
<li>When you remove something by pressing Delete or Backspace.</li>
<li>When you cut text form the field or paste it in.</li>
</ul>

<p>You may be tempted to use the <code>OnObjectKeystroke</code> trigger for something like this, but <code>OnObjectModify</code> gets you more bang for the buck: It handles cut and paste, and doesn&#8217;t require <a href="http://sixfriedrice.com/wp/script-triggers-using-the-keystroke-trigger/" title="An article about keystroke triggers">all the complexity</a> of keystroke triggers.</p>

<h2>The Code</h2>

<p>I&#8217;ll let you explore David&#8217;s sample file for the full scoop, but the core of his technique can be found in two places. First, he uses an exploded key filtering technique, which I won&#8217;t cover her, except to say that the idea is to process some text data and produce a multi-line key that includes partial match values. In other words, if the value is &#8220;Test&#8221; then the key would match &#8220;T&#8221;, &#8220;Te&#8221;, &#8220;Tes&#8221; and &#8220;Test.&#8221; In this way, you can type all-or-part of the value and see the results. Look at David&#8217;s <code>ExplodeToMultikey</code> custom function to see how he accomplishes this.</p>

<p>If you prefer, you can use scripted finds and a list view layout to do your filtering instead.</p>

<p>But the interesting part is this very simple trigger script:</p>

<pre><code>Set Variable [$currentObject; Get ( ActiveLayoutObjectName )]
Commit Records/Requests []
Go to Object [ $currentObject ]
Set Selection [ Start: Length (Get(ActiveFieldContents)) + 1]
</code></pre>

<p>That&#8217;s it. This script really just does two things:</p>

<ol>
<li>It commits the record, causing anything you&#8217;ve typed in the filter field to take effect.</li>
<li>It returns you to the field, so if you type again, your keystrokes will go right on the end of the field.</li>
</ol>

<p>In this way, as you type, your changes reflect immediately. Very cool.</p>

<blockquote>
  <p>Note: If you were using finds instead of exploded keys, you would add a a few more steps to your script to switch to Find mode, build a find request or two, and then perform the find.</p>
</blockquote>

<p>You can <a href="http://sixfriedrice.com/wp/wp-content/uploads/2009/01/spotlight-filter.zip" title="David Graham’s filter example file.">download the working file right here</a>.</p>

<p>Thanks to David for the great technique!</p>
]]></content:encoded>
			<wfw:commentRss>http://sixfriedrice.com/wp/script-triggers-filter-as-you-type/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://sixfriedrice.com/wp/wp-content/uploads/2009/01/modify-filter.mov" length="570965" type="video/quicktime" />
		</item>
	</channel>
</rss>
