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.

VariablesFromFields Custom function ignores quotation marks

Featured Replies

Hi all

I have used a custom function created by Fabrice Nordmann that holds all fields on a layout in global variables using the field name as the the variable name.

I have found this function to be extrememly useful so far, but have found a limitation - If a field contains a quotation mark ", the variable will not be created.

Here is the function:


/*

VariablesFromFields ( )

by Fabrice Nordmann

with thanks to Agnès Barouh, Ugo di Luca and Daniele Raybaudi



v2.1 : Sept 2007. Fixed a bug with carriage return

v2 : no more parameter is needed (was VariableFromFields ( start ))



Loads all current layout fields in named global variables



i.e. current layout has :

field "A" that contains "1",

field "B" that contains "2",

field "C" that contains "3"



Evaluating this function will result in 3 global variables :

$$A will contain "1"

$$B will contain "2"

$$C will contain "3"



Among other ways of evaluating this calculation, you can use :

- a Set Variable script step [ $temp ; VariablesFromFields ( ) ]

- an unstored calculation field on your layout and defined as = VariablesFromFields ( )

   In this case, you will need to refresh window to load variables.



This demo uses an unstored calculation : the field has to be named "VariablesFromFields, and must be put first on layout.

-----------------*/



Let([

_fields = FieldNames ( Get ( FileName ) ; Get ( LayoutName ) ) ;

_end = ValueCount ( _fields ) ;

$$cfVFF_counter = Case ( IsEmpty ( $$cfVFF_counter ) ; 1 ; $$cfVFF_counter > _end ; "" ; $$cfVFF_counter + 1 ) ;

_fieldName = GetValue ( _fields ; $$cfVFF_counter ) ;

_value = Substitute ( GetField ( _fieldname ) ; ¶ ; "¶" ) ;

_textEval = "let ( $$" & _fieldname & " =" & Case ( IsEmpty ( _value ) ; """" ;  """ & _value & """ ) & "; "")"

];

Case (

$$cfVFF_counter <= _end ; If ( _fieldName ≠ "VariablesFromFields" ; Evaluate ( _textEval ) & VariablesFromFields ( )

)

))

My coding skills aren't fantastic, but I'm always willing to learn and try to solve the problem.

I'm assuming the problem lies within this segment of code?

_textEval = "let ( $$" & _fieldname & " =" & Case ( IsEmpty ( _value ) ; """" ; """ & _value & """ ) & "; "")"

];

Could anybody please guide me through this line?

Your help would be greatly appreciated

Lee

Hi

try to change this:

_value = Substitute ( GetField ( _fieldname ) ; ¶ ; "¶" )

to:

_value = Substitute ( GetField ( _fieldname ) ; [ """ ; """ ] ; [ ¶ ; "¶" ] )

  • Author

Thanks Daniele

That worked a treat

Lee

Hi guys!

Many thanks. It's now fixed on FMfunctions.com

  • 2 months later...
  • Author

Hi Fabrice

I noticed that the function was failing recently and remembered I had switched on smart quotes in the file options.

Could I recommend that the following line:

_value = Substitute ( GetField ( _fieldname ) ; [ """ ; """ ] ; [ ¶ ; "¶" ] )

be updated to:

_value = Substitute ( GetField ( _fieldname ) ; [ """ ; """ ] ; [ ¶ ; "¶" ] ; [ Char (8220) ; "" & Char (8220) ] ; [ Char (8221) ; "" & Char (8221) ] ) ;

to cater for smart quotes.

Thanks

Lee

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.