FileMaker – マルチプルスクリプトパラメータの受け渡し

FileMaker – Passing Multiple Script Parameters
以下の blockquote部分は上記出典ページの段落、直後の日本語は内容の拙訳です。
拙訳への具体的な「ちげーよバカ!」な突っ込みは大歓迎です。
※ 万一のトラブルは、出典サイトはもちろん、(たとえそれが僕の拙訳のせいだとしても) 一切関知しませんのであしからず。

素晴らしいカスタム関数を発表してくれた sixfriedrice.com の Jesse Antunes / Geoff Coffey に感謝します。


I can think of hundreds of times when I found myself pounding my head against the desk because I had to define yet another global field just to pass a simple value from one script to another. Like you, I myself hate to have lots of cruft clogging up my databases. Luckily, FileMaker 7+ gave us the wonderful addition of script parameters to help relieve this plight. Sometimes, even this isn’t enough and that’s where passing multiple parameters takes over.

あるスクリプトから別のスクリプトに対して、単純な値を渡すためだけに、グローバルフィールドをもうひとつ定義しなければならなくなって…「あーもー!」てなもんで、机に頭を打ちつけていた…あの光景を何百回も思い出すのことあります。
あなたたちと同じで、わたしもデータベース開発作業の足を引っ張るたくさんのあれやこれやに辟易していました。
幸運にも、FileMaker 7 以降では、こんな状況を少しは楽にしてくれる スクリプト引数なるものが追加されたわけですが、複数の引数を受け渡したいとかいうことになると、そんなもんじゃ足りなくなることもよくあります。

Whenever a script is chosen in a perform script step, Filemaker shows a box for an optional script parameter. You can type in whatever your programming heart desires or you can click the edit button and take advantage of Filemaker’s many built-in functions to construct a parameter. Many times, when presented with this option you probably find yourself thinking . . . Boy, I wish I had space for a bunch of different parameters. Well with the use of that tiny edit button, a couple of Filemaker’s functions and a little bit of ingenuity this actually ends up being doable. To pass multiple parameters in filemaker we are basically going to make a ¶ delimited list and then crowbar individual parameters out using the MiddleValues().

スクリプト実行が選択されたときはいつでも、オプショナルなスクリプト引数のためのボックスが表示されます。
あなたのプログラミング魂の赴くままに入力することも、編集ボタンを押して、ビルトインの関数を利用して引数を組み立てることもできます。
そのとき何度もこう思ったはずです。
「にいちゃんよー、一連のパラメータを書く場所がなんとかならんかねー。そのちっぽけな編集ボタンを使って、いくらかの FileMakerの関数を使ったひと工夫でよー。」
FileMakerにおいて、複数の引数を受け渡すには、基本的に、改行区切りリストにぶちこんで、個々の引数を MiddleValues ( ) を使って無理矢理引っ張りだすことになるわけです。

Ok, let’s say we are trying to create a new line item for an order we are going to fulfill for 3 iPhones at a price of $499. We don’t want to have to put the part number (iPhone), the description (”The coolest phone I have ever seen. Wow, it’s also really cheap!”) the quantity(3) and the price($499) in a bunch of different globals to pass our script, so we will just send them in using the script parameter. To do this, select the perform script step and pick the script you are going to call. Then hit the edit button next to the “Optional Script Parameter” box. Filemaker’s trusty old calculation window will pop up and you’re ready to roll. All you have to do is make the parameters you would like to pass into a list like so:

では、たとえば今、499ドルの 3つの iPhone 用に 新しい項目 を作りたいとしましょう。

部品番号 (iPhone) とか、説明 (”The coolest phone I have ever seen. Wow, it’s also really cheap!”) とか、数量 (3)とか、価格 ($499)とかを、スクリプト引き渡しのために一連の別個のグローバルにいちいち入力したかないので、スクリプト引数を使って受け渡したいというわけです。

そのために、スクリプトステップを実行を選択して、実行するスクリプトを指定して、オプションのスクリプトパラメータの横にある編集ボタンをクリックします。
FileMaker の古式ゆかしい計算ウィンドウがポップアップしたら準備完了です。
やんなきゃいけないことは、受け渡したい引数を作ることです。

こんな感じで…

Hit Ok and you are done with your parameter passing. Now comes the part where you pop the values you want from the script parameter. To do this we are just going to simply use the MiddleValues() function. The complete signature of Middlevalues() is:

OKをたたいて引数受け渡しは完了。
さて、お次ぎは、お好みの値を、スクリプト引数から引っ張りだすわけです。
これには、シンプルに MiddleValues ( ) 関数を使うことになります。
この場合の 完全な MiddleValues ( ) の書式は…

Note: Thanks to David Richards (from the comments) and Genx (from FMForums.com for pointing out that you can simplify these calcs using GetValue instead of MiddleValues. We needed FileMaker 7 support for this particular setup, but if you can live with 8+ only, they’re absolutely right. GetValue does not include the trailing ¶ so you can avoid all the mumbo jumbo about cleaning that up.

Note: David Richards (コメント欄から) と Genx (FMForums.com から) に感謝します。
これらの計算式は、MiddleValues の代わりに、GetValue を使うことでシンプルになることを指摘してくれてありがとう。
私たちは、この特有のセットアップで FileMaker 7 をサポートしなくちゃならないけど (だから MiddleValues で行くわけだけど)、8以降のみなら、彼らは完全に正しいわけです。
GetValue だったら、改行を引きずることもないから、余計なジュゲムジュゲム的記述を削除できるね。

The sole purpose of this function is taking a list of ¶ separated values, exactly like we created in the previous step, and select the values you specify from it. For instance, let’s say we are in the script we called in the first step and we want to get the quantity out of the script parameter. All we would need to do is execute the following bit of code:

この関数の唯一の目的は、(前のステップでやったように) 改行区切りリストを得ることと、そのリストから指定した値を取得することです。
たとえば、最初のステップで呼び出したスクリプトのなかにいて、スクリプト引数から 数量を取り出したいとしましょう。
下記のちょろっとしたコードを実行するだけです。

This step tells Filemaker to start from the third value in the script parameter and return one value which is effectively just saying give me the third value in the list. If you want the fourth value, the price, just change the number 3 to a 4. The one will always stay the same because you wouldn’t really want to get more then one value out of the script parameter at a time. It wouldn’t really make sense in a typical script.

We have the value out, we still aren’t quite finished. The MiddleValues function doesn’t get ride of the annoying ¶ that we tacked on the end of our parameters so to delete it we have to add the following code:

このステップは、FileMaker に スクリプト引数の 3番目の値から 一行取得するということです。
(実際には、リストの3番目をよこせと言ってるのと同じ)
もし、4番目の価格の値が欲しいなら、3を4に変えるだけのことです。
一度に複数の値をスクリプト引数から取り出したいことはないでしょうから、一行取得というのはいつも同じです。
典型的なスクリプトではあんまり役にはたたないかもしれません。

値を取り出せはしましたが、まだ終わりではありません。
MiddleValue 関数は、パラメータ全体をつなぐ改行を引きずったままなので、改行を削除するためには、以下のコードを追加してやらなければなりません。

This code is a little confusing but it is basically saying if we have a ¶ on the end of our parameter take it off.

Now that you have seen how we plan on getting the values out, you are probably thinking to yourself… What happens if I pass a ¶ in the middle of one of my parameters. This isn’t exactly out of the realm of possibility and it would clearly break your code. For instance if you changed the description on the iphone to read:

このコードは、頭が少しこんがらがるかもしれませんが、要は、パラメータの最後に改行があれば、それを削除しろと言っているだけのものです。

さて、値を取り出そうとする方法を見てきたわけですが、おそらくこう思っていらっしゃるでしょう。
「パラメータの中に改行を含む値を持ちたい場合はどうなるん?」
それはあり得ない領域の話ではありませんし、そうなれば明らかにアウトです。
たとえば、iPhone の説明をこう変えたとしましょう。:

Unfortunately, Filemaker will mush (concatenate for you technical types) everything together and create the following list:

残念ながら、FileMaker は、すべてを一緒に (数珠つなぎで) まぜこぜにして、以下のようなリストを吐き出すでしょう。

Now, everything has been shifted down one because of that extra ¶ and we can no longer get the price, quantity nor description that we expect. To take care of this we have to escape the ¶ so that it turns it into just a symbol rather then turning it into a new line in your text. To implement this change we will have to change how we create our list. I know I lied to you, you weren’t quite done with creating your parameter list. Here is the function you will need:

こうなると、すべては、邪魔な改行のせいで一段下がってしまいます。
価格も数量も、期待される形での説明も取得できなくなります。
このことの面倒をみるには、改行をどうにかエスケープさせて、テキストを改行させるためだけのシンボルと扱うようにしなければなりません。
この変更を実装するためには、リストの作成方法を変更しなければなりません。
はい、嘘ついてました。パラメータリストの作成はまったく終わっていませんでした。
以下が、必要な関数です。

Using our new code we would rewrite our last list to:

新しいコードをつかうには、先述のリストも書き換える必要があります:

Not only does this list look a heck of a lot cooler, but it is more functional and a LOT easier to read. OK, we have a custom function to add parameters to a list, we should probably create one to get all that information out so we don’t have to type that horrible blob of code ever again:

これでむちゃくちゃかっちょいーだけでなく、より機能的で、ものすごく読みやすくなったわけです。
さあ、パラメータを追加するカスタム関数もあります。
あのゾッとするコードの一塊をもうタイプしなくてすむようなすべての情報を一緒にしたヤツを作る必要があります:

Before you go off and pass around parameters all willy nilly, there is one final warning when using this style of parameter passing. To demonstrate it, Let’s go back to our iPhone example. Say that you don’t want to include the quantity just yet, but you still want to send over the price and description. If you tried the following:

さてパラメータを受け渡しまくり始めるには、まだ早いです。
このパラメータ受け渡しスタイルを使うには、否応無しに、最後の警告をひとつしなければなりません。
デモを行うために、例の iPhone の例に立ち返りましょう。
数量を含めることは必要ないけれど、価格と説明の受け渡しは必要だとしましょう。
もし以下のようにやってみると…

The $499 will go into the quantity field because your script that creates the line item thinks that the quantity is the third value, but because the quatity isn’t there the price has shifted up into the third position. To alleviate this problem you just need to make sure that you ALWAYS pass all the parameters to a script, even if one is empty. So your parameter list should look like this:

スクリプト的には、数量は3番目の値だと思っているわけですから、$499 は、数量フィールドに入ってしまいますが、実は、数量はそこではなく、その3番目の位置には、繰り上がって価格が来ることになります。
この問題を軽減するには、(たとえ空っぽの値があったとしても)「いつどんなときも」すべてのパラメータをスクリプトに受け渡すことが条件になります。
したがって、パラメータリストはこうなります:

Hopefully, many of you find this quite useful and it will help you build more powerful and less cluttered databases. For those who would like a more technically advanced way of passing parameters, where you can actually associate each parameter with a name, such as qty = 2, then check back soon for another article.

願わくば、みなさんが、よりパワフルでよりすっきりしたデータベースを作る上で助けになり、有益であると思っていただければよいのですが。
それぞれのパラメータを name と結びつけた (たとえば、gty = 2 みたいに) もっと技術的に進歩的なパラメータ受け渡し方法をお望みの向きには、別記事で。


  1. FileMaker – マルチプルスクリプトパラメータの受け渡し (このエントリ)
  2. マルチプルパラメータのスクリプトへの受け渡し – 応用編
  3. FileMaker Dictionary 関数

コメント

  1. […] FileMaker – マルチプルスクリプトパラメータの受け渡し […]

  2. […] FileMaker – マルチプルスクリプトパラメータの受け渡し […]

  3. […] FileMaker – マルチプルスクリプトパラメータの受け渡し […]

  4. […] FileMaker – マルチプルスクリプトパラメータの受け渡し […]

タイトルとURLをコピーしました