Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How do I make One script separatley process Many fields

Featured Replies

Or how do I make my scripts more reusable.

 

Perfect example; Phone number formating.

 

Here is the essence of the script:

Set Variable [$AreaCode; Value:Left ( Get ( ActiveFieldContents ); 3)]

Set Variable [$digits3; Value:Middle ( Get ( ActiveFieldContents ); 4; 3)]

Set Variable [$digits4; Value:Middle ( Get ( ActiveFieldContents ); 7; 4)]

Set Field [Tutor::HomePhone; "(" & $AreaCode & ") " & $digits3 & "-" & $digits4 ]

 

Rather than hard coding this script to every field; creating a new script for each instance; how can I make a general reference to the active field?  Thus alowing me to have ONE script that can be reused for many similar fields.

 

Jason

Perfect example; Phone number formating.

 

This is not a perfect example – not even a good one; phone number formatting can be offloaded to an auto-enter calculation for the field, e.g.

 

Case ( 
  Length ( Trim ( self ) ) = 10 ;
  Let (
    s = Trim ( self ) ;
    area = Left ( s ; 3 ) ;
    digits3 = Middle ( s ; 4 ; 3 ) ;
    digits4 ; Right ( s ; 4 )
    ] ;
    "(" & area & ") " & digits3 & "-" & digits4
    ) ;
  self // or use different formats for different lengths
)
 
Note the use of self to refer to the field whose auto-enter calculation you're editing.
 
And then of course you can put this logic into a Custom Function and simply call, say, FormatAsPhone ( self ), where the function could decide on the appropriate format based on the length.

I presume that for this case, the script is assuming that the currently active field is the target of the formatting. In that case, you case simply not specify a target field for the Set Field script step, and it will target the active field instead.

 

There isn't a single best way to make scripts reusable in general. What techniques we use to make a script more reusable depends on what exactly the script does, and how exactly we want to reuse it. One general guideline I can suggest is that it's usually not a good idea to try to make a script or calculation reusable until after the need for reuse actually comes up; otherwise, you can easily waste effort making something more general in a way that it may never actually need to be. Comics have been written about the urge for premature generalization. If you're interested in more specific techniques, check out some of the modules at ModularFileMaker.org, which have been written specifically to be reusable.

 

In your case, if you want to use the snippet above as the target of a script trigger you can apply to different fields, it would be fine with just not specifying the target of the Set Field script step. (If you're using this to clean-up data input, it might be better to use an auto-enter calculation on those fields, as eos says, that call a re-usable custom function like this one (which uses this one)).

  • Author

This is awesome !! Thanks guys !!

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.