<?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; FM7</title>
	<atom:link href="http://fmcollective.com/category/fm7/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>Roll Your Own Edit Mode</title>
		<link>http://fmcollective.com/2007/05/19/roll-your-own-edit-mode/</link>
		<comments>http://fmcollective.com/2007/05/19/roll-your-own-edit-mode/#comments</comments>
		<pubDate>Sun, 20 May 2007 03:16:56 +0000</pubDate>
		<dc:creator>Ernest Koe</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[FM7]]></category>
		<category><![CDATA[FM8]]></category>
		<category><![CDATA[FM8.5]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://fmcollective.proofgroup.com/?p=29</guid>
		<description><![CDATA[The Problem
As FileMaker developers, we take a lot of things for granted.  For example, FileMaker&#8217;s Browse Mode/Find Mode feature is actually pretty slick; just place a field on a layout and it becomes both a data-update field as well as a query field without additional coding. However, when a layout is set to &#8220;save [...]]]></description>
			<content:encoded><![CDATA[<h2>The Problem</h2>
<p>As FileMaker developers, we take a lot of things for granted.  For example, FileMaker&#8217;s Browse Mode/Find Mode feature is actually pretty slick; just place a field on a layout and it becomes both a data-update field as well as a query field without additional coding. However, when a layout is set to &#8220;save record changes automatically&#8221;, the frequency of people <em>thinking</em> they are in Find mode when they are actually happily clobbering data is enough to drive the most laissez-faire FileMaker developer nuts.</p>
<p>Sometimes,  calling such problems &#8220;training-issues&#8221; just isn&#8217;t enough.</p>
<p>One solution is to roll your own Edit Mode feature. This technique uses the power of global variables in FileMaker 8+. In this example, I am going to combine scripts, a global variable and a custom privilege set to regulate users&#8217; record-edit access.</p>
<p>Note: this article in intended to illustrate a general technique, do not rely solely on this example to secure your database.</p>
<p><span id="more-29"></span></p>
<p>The screenshots below are from a Mac but this tip is platform-agnostic.<a href="http://fmcollective.com/wp-content/uploads/2007/05/rollyourowneditmode.zip" title="Example File"></a></p>
<p><a href="http://fmcollective.com/wp-content/uploads/2007/05/rollyourowneditmode.zip" title="Example File">Download the Example File</a></p>
<p>Note: the top level account is &#8220;admin&#8221; with no password</p>
<h2>Step-by-Step</h2>
<p><strong>1. Create the table</strong><br />
In this example, I am going to start with a new file. I have defined a table called &#8220;contacts with a few basic fields.</p>
<p><a href="http://fmcollective.com/wp-content/uploads/2007/05/ryo_create_table.png" title="create table"><img src="http://fmcollective.com/wp-content/uploads/2007/05/ryo_create_table.png" alt="create table" height="304" width="402" /></a></p>
<p>Don&#8217;t worry about the &#8220;lock status&#8221; field for now; that is an interface bell-and-whistle that I added to give the user some visual feedback. Check out the example file to learn more about that later.<br />
<strong><br />
2. Create the &#8220;toggle&#8221; script</strong><br />
Next, I am going to create a basic script that toggles the edit mode.  The script is going to use a global variable as a switch. It sets a global variable to either 1 or zero each time the script is called.</p>
<p>I have chosen to name my global variable switch <code>$$__locked</code> but you could call it whatever you wish. Just make sure it is a <strong>global</strong> variable because we want the variable to hold on to its value after the script is run.</p>
<p>The script works by checking first to see if <code>$$__locked</code> is &#8220;on&#8221; (i.e. has a value that isn&#8217;t zero or empty). If <code>$$__locked</code> is &#8220;on&#8221;, the script turns our switch &#8220;off&#8221; by setting  <code>$$__locked </code>to zero. <code></code></p>
<p><a href="http://fmcollective.com/wp-content/uploads/2007/05/ryo_script.png" title="ryo_script.png"><img src="http://fmcollective.com/wp-content/uploads/2007/05/ryo_script.png" alt="ryo_script.png" height="281" width="439" /></a></p>
<p><strong>3. Configure record level access </strong></p>
<p>We need to tell FileMaker to check the global <code>$$__locked</code> before allowing our user to make record changes.  Since record access is controlled by FileMaker privilege,  I am going to  go over to the Define&gt;Accounts &amp; Privileges&#8230; menu and create a User account with a custom privilege set called &#8220;User&#8221;&#8230;</p>
<p><a href="http://fmcollective.com/wp-content/uploads/2007/05/ryo_define_accts.png" title="modify accounts"><img src="http://fmcollective.com/wp-content/uploads/2007/05/ryo_define_accts.png" alt="modify accounts" height="170" width="331" /></a></p>
<p><a href="http://fmcollective.com/wp-content/uploads/2007/05/ryo_edit_account.png" title="ryo_edit_account.png"><img src="http://fmcollective.com/wp-content/uploads/2007/05/ryo_edit_account.png" alt="ryo_edit_account.png" height="225" width="326" /></a></p>
<p>To configure the record data access setting, I select &#8216;Custom Privileges&#8217; from the &#8216;Records&#8217; pull down menu of the &#8216;Edit Privilege Set&#8217; screen&#8230;</p>
<p><a href="http://fmcollective.com/wp-content/uploads/2007/05/ryo_custom_priv.png" title="ryo_custom_priv.png"><img src="http://fmcollective.com/wp-content/uploads/2007/05/ryo_custom_priv.png" alt="ryo_custom_priv.png" height="314" width="498" /></a><a href="http://fmcollective.com/wp-content/uploads/2007/05/ryo_modify_data_access.png" title="ryo_modify_data_access.png"> </a></p>
<p>I am going to control access to the &#8220;contacts&#8221; table by highlighting it and changing the &#8216;Edit&#8217; privilege to &#8216;limited&#8230;&#8221;</p>
<p><a href="http://fmcollective.com/wp-content/uploads/2007/05/ryo_record_access.png" title="ryo_record_access.png"><img src="http://fmcollective.com/wp-content/uploads/2007/05/ryo_record_access.png" alt="ryo_record_access.png" height="265" width="488" /></a></p>
<p>My goal is to use a calculation expression to govern the user&#8217;s record modification activity. Records can be edited when:</p>
<blockquote><p><code>not $$__locked</code>.<code></code>..</p></blockquote>
<p><a href="http://fmcollective.com/wp-content/uploads/2007/05/ryo_edit_test.png" title="ryo_edit_test.png"><img src="http://fmcollective.com/wp-content/uploads/2007/05/ryo_edit_test.png" alt="ryo_edit_test.png" height="369" width="483" /></a></p>
<p>FileMaker will evaluate the expression <code>not $$__locked</code> each time the user tries to modify a record. If <code>$$__locked</code> is zero or empty, the expression <code>not $$__locked will</code> evaluate to true (not locked) and the user will get to edit records. If <code>$$__locked</code> is &#8220;1&#8243;, our expression will evaluate to false and our user will be blocked from making any changes to &#8216;contact&#8217; records.</p>
<p><strong>4. Bells &amp; Whistles</strong></p>
<p>In the example file, you&#8217;ll note that I have added couple of simple re-login scripts to toggle between my &#8220;user&#8221; account and my &#8220;admin&#8221; account.</p>
<p>Finally, let&#8217;s cap it off by attaching a button to our script and by adding a &#8220;lock status&#8221; calculation field to create a simple indicator of the record lock status.</p>
<p><strong> </strong></p>
<p><a href="http://fmcollective.com/wp-content/uploads/2007/05/ryo_simple_ui.png" title="ryo_simple_ui.png"><img src="http://fmcollective.com/wp-content/uploads/2007/05/ryo_simple_ui.png" alt="ryo_simple_ui.png" /></a></p>
<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://fmcollective.com/2007/05/19/roll-your-own-edit-mode/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
